c# - Performance in linq to entity queries between linq and lambda? -


i have doubt in query it's little bit slow , want know what's best performance.

let's present first example:

var result = tablea in context.tablea              join tableb in context.tableb on tablea.id equals tableb.id              *some conditions*              select new {                  tablea.id,                  tablea.name,                  another_name = tablea.tablec.name                  some_operation = tableb.price * tableb.tabled.some_coeficient                  another_operation = tableb.tablee.sum(c=> c.some_value)              }; 

this have right (after query perform in variable result.tolist().

mi question if better in levels of performance make:

  1. a query lambda expressions? keeping select new {....} part.
  2. a query select new {....} part after tolist()?

what recommend me do?

  1. it same. query expressions converted non-query-expression equivalent.

  2. you'd need use select new { tablea, tableb } or similar anyway, use both variables after tolist... slower then:

    • all fields pulled database rather used
    • the projections (including sum etc) happen after fetching values database, rather within database. involve making more database requests, access tablea.tablec etc.

you should @ generated sql, run in sql profiler work out what's slow, consider more indexes etc.


Comments