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
I'm in the same situation. I think that with EF is very easy to fall in a 101 query problem.
A solution can be to create a partial class of your Seller class (generated by EF) and implement a GetSubclassNameQ that return a IQueryable, and a GetSubclassNameQFull that return a IQueryable with eager loading.
public partial class Seller{
public IQueryable GetRecommendationsQ(EntityContainer entitycontainer) {
return entitycontainer.Recommendations;
}
public IQueryable GetRecommendationsQFull(EntityContainer entitycontainer) {
return this.GetRecommendationsQ(entitycontainer).Include("Recommendations.User");
}
public IQueryable GetRecommendationsQ() {
return GetRecommendationsQ(new EntityContainer());
}
public IQueryable GetRecommendationsQFull() {
return this.GetRecommendationsQ().Include("Recommendations.User");
}
}