Entity Framework - Eager loading related entities

后端 未结 4 1375
野趣味
野趣味 2021-02-13 19:17

I\'m using Entity Framework 4 with MVC and need to ensure any referenced entities I want to use in my view have been loaded before the controller method returns, otherwise the v

4条回答
  •  佛祖请我去吃肉
    2021-02-13 20:09

    This is an old question, but in EF6 you can accomplish loading dependent objects on an entity like this:

    context.Entry(seller).Collection(s => s.Recommendations).Query().Include(r => r.User)).Load();
    

    That would load all Recommendations and their related Users for the given seller

提交回复
热议问题