What I am trying is to load all the A entities in the database together with B entities. The relationship between them is Every A entitiy has one B entitiy.
The project I am working on has a repository pattern and it has an All() method as below.
public class EFRepository<T> : IRepository<T> where T : class, IObjectWithChangeTracker
{
private IObjectSet<T> objectset;
private IObjectSet<T> ObjectSet
{
get
{
if (objectset == null)
{
objectset = UnitOfWork.Context.GetObjectSet<T>();
}
return objectset;
}
}
public virtual IQueryable<T> All()
{
return ObjectSet.AsQueryable();
}
}
Is there any way that I can force B entities to eager load. What I’ve found is there there is no Include method on the IQueryable that returns from the All() method. I am happy to add a new member to repositroy so it can allow the client to use eager loading. But how can I do it?
You can create your own extension method which will allow you to use
Include(path)against anyIQueryable<T>:There’s a full explanation on Julie Lerman’s blog: http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-5-iobjectset/