开发者

When are navigational properties loaded?

If an entity A has a FK relationship with entity B, and is represented as a n开发者_JAVA技巧avigational property in entity A inside EF4, when are data from entity B loaded? Is it upon creating an instance of A, or only when B is accessed from within A?


It depends on loading method:

  • Eager loading - the query loading A contains .Include(a => a.B). In such case both A and related Bs are loaded during query execution
  • Lazy loading - only A is loaded during the first query and if it is still in scope of living context it can trigger lazy loading of B once navigation property accessed first time
  • Explicit loading - you will manually trigger loading by calling context.LoadProperty(a, "B");


You're going to want to look into Loading Related Objects, perhaps you're more interested in eager loading.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜