Junk loading in EntityFramework with DbContext.Database.SqlQuery

In EF 4, is it possible to load navigation properties using the sql entry on DbContext.Database.SqlQuery or DbContext.Set<T>().SqlQuery ? It looks like I have no navigation properties.

Edit

It seems I can do eagerloading with DbContext.Set (). SqlQuery, just not DbContext.Database.SqlQuery. Any idea why?

+8
tsql eager-loading
source share
1 answer

DbSet.SqlQuery works differently than Database.SqlQuery. The DbSet method is applied to this set of entities. It should return objects of this type, and by default returned objects will be tracked. Database.SqlQuery can return any object (possibly not an entity), and returned objects are never tracked by context. You can also take a look at msdn to compare both methods:

Database.SqlQuery - http://msdn.microsoft.com/en-us/library/gg679117(v=vs.103).aspx

DbSet.SqlQuery - http://msdn.microsoft.com/en-us/library/system.data.entity.dbset.sqlquery(v=VS.103).aspx

+4
source share

All Articles