I have some distraction when i speak with my collegue and he said that Include in EF and Join in SQL is different things. Can you explain is it true? If yes, explaint in what difference is?
Thanks.
When querying EF through linq or lambda expressions, you only need join statements if the underlying schema doesn't provide FKs, and thus you don't have navigation properties on the objects.
On the other side, include (eager loading) and lazy loading can only work if there are FKs, because it uses the navigation properties.
The underlying sql in both cases will use joins (as sql has no "navigation property" concept).
As for performance, it depends on situations. Lazy loading vs Eager loading (so in FK scenario) can be a difficult choice.
I usually go with lazy loading, useful when you have a large main result, but you need "join" data only of a few items of the whole resultset.
If you know ahead that you'll need the join data of the whole resultset, eager loading could be better for performance. I'd suggest to experiment and see for yourself.
Taken from Understanding EF. Include vs Joins
Includeisn't a SQL Join itself; it is a function which accepts a string specifying which related objects should be loaded from the database. Entity framework then uses one or more joins to produce the full object graph. These may be inner or outer, left or right joins depending on the relation of the objects.ToTraceStringmsdn.microsoft.com/en-us/library/… to examine a query and see how it will be executed in SQL. In some cases, a more efficient query can be formulated by specifying your own join statements.