On LinqPad you should be able to view the SQL statement generated from the LINQ statement.
In my opinion there is always a debate between using let
or navigation properties in LINQ to Entities (or LINQ to SQL). Sometimes a simple JOIN
might work better too. In other words it all depends on how your LINQ provider (Entity Framework) optimizes your specific query into SQL statements.
I would suggest you test your query with all let/join/navigation
to see the generated SQL statement.
You can use ObjectQuery
under System.Data.Objects
in your code to view realtime SQL statement in case you don't have SQL profiler or intellitrace tool:
((ObjectQuery)anyLinqQuery).ToTraceString();
Also you can try using multiple from
clause:
var output = from i in ExpenseItems
from exp in i.ExpenseItemAccountings
where ....
select new {...};
or
var output = from i in ExpenseItems
from exp in i.ExpenseItemAccountings.DefaultIfEmpty()
where ....
select new {...};