I am using generic repository pattern with methods:
private ObjectQuery<T> ObjectQueryList()
{
var list = CamelTrapEntities.CreateQuery<T>(EntitySetName);
return list;
}
public IQueryable<T> List()
{
return ObjectQueryList();
}
Metod List() returns IQueryable<T>, becase IQueryable<T> is easy to mock. I also have extension method:
public static IQueryable<T> Include<T>(this IQueryable<T> obj, string path)
{
if (obj is ObjectQuery<T>)
(obj as ObjectQuery<T>).Include(path);
return obj;
}
This method is used outside of repository to get entity list with navigation properties already loaded, for example: List.Include("CreatedBy"). The problem is that it doesn't work. All includes are ignored. when I change List() method to
public ObjectQuery<T> List()
{
return ObjectQueryList();
}
everything works fine.
How should I implement repository pattern to be able to execute more complex queries?