Eager loading in EntityFramework with DbContext.Database.SqlQuery

后端 未结 1 997
你的背包
你的背包 2020-12-19 03:46

In EF 4, can I do eager loading of navigation properties by writing sql on DbContext.Database.SqlQuery or DbContext.Set().SqlQuery? I don\

相关标签:
1条回答
  • 2020-12-19 04:14

    DbSet.SqlQuery works differently than Database.SqlQuery. The method on DbSet applies to the given entity set. It has to return entities of the given type and by default the returned entities will be tracked. Database.SqlQuery can return any object (possibly not an entity) and the returned objects are never tracked by the context. You may also want to 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

    0 讨论(0)
提交回复
热议问题