views:

285

answers:

1

Should I avoid using Include in queries, or I can rely on the EDM that when it creates the query it excludes from the query items that already exist in the OSM?

+2  A: 

I'm pretty certain that EF4 will use anything currently in the ObjectStateManager and only load objects it doesn't already have, but the best way to be sure is to simply test it with SQL Profiler running and see if that holds true for the way you're using it.

Certainly using the Include() method is recommended by the EF team, but if you choose to load the related rows later the ObjectStateManager will do 'relationship fix-up', which can be a very powerful feature to take advantage of.

Have a look at this blog entry:

http://blogs.msdn.com/alexj/archive/2009/10/13/tip-37-how-to-do-a-conditional-include.aspx

You'll find plenty of great articles on his blog regarding entity-framework.

Timothy Walters
On the other hand let's not forget that mapping abstracted includes is the one of the biggest performance cost in EF
Shimmy