I have a doubt in a query that it's a little bit slow and i want to know what's best for performance.
Let's present this first example:
var result = from tableA in context.TableA
join tableB in context.TableB on tableA.id equals tableB.id
where *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 is what i have right now (after this query i perform in another variable a result.ToList()
.
Mi question is if would be better in levels of performance to make:
select new {....}
part.select new {....}
part after the ToList()
?What do you recommend me to do?
It would be exactly the same. Query expressions are basically converted to the non-query-expression equivalent.
You'd need to use select new { tableA, tableB }
or something similar anyway, so that you could use both variables after ToList
... but it would probably be slower as then:
tableA.TableC
etc.You should look at the generated SQL, run it in the SQL profiler to work out what's slow, consider more indexes etc.
See more on this question at Stackoverflow