When querying with 'Include', does the EF checks if objects already exist in object state manager?

1.6k views Asked by At

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?

1

There are 1 answers

1
Timothy Walters On BEST ANSWER

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.