Configure Related Entities on modelBuilder instead

2019-09-01 16:39发布

Guys it is possible configure on modelBuilder to set which Entities get related 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

1条回答
你好瞎i
2楼-- · 2019-09-01 17:18

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.
查看更多
登录 后发表回答