开发者

Configure Related Entities on modelBuilder instead on Include method

Guys it is possible configure on modelBuilder to set which Entities get rel开发者_StackOverflowated entities instead i use Include method on my LINQ queries?

PROS: I don't need to use Include Method on queries provided by my IRepository Interface, nor reference EntityFramework.dll


No it is not possible. You must either use eager loading, lazy loading or explicitly load each relation:

  • Eager loading - calling Include. This will load relation during initial query in single database roundtrip.
  • Lazy loading - making navigation properties virtual. This will load each navigation property when the property is first used by your code. It creates separate database roundtrip for each navigation property.
  • Explicit loading - you will manually tell property to load (the approach depends on used API - DbContext x ObjectContext). Again this will create separate roundtrip for each navigation property.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜