I have an implementation of a Generic Repository in Entity Framework which I am trying to improve to use the .Include(..) function provided by EF instead of including the na
protected internal IQueryable Filter(Expression> predicate, params Expression>[] includeProperties)
{
var query = RetrieveQuery();
if (predicate != null)
{
query = query.Where(predicate).AsQueryable();
}
if (includeProperties != null)
{
query = _queryableUnitOfWork.ApplyIncludesOnQuery(query, includeProperties);
}
return (query);
}
And this method called there
public IQueryable ApplyIncludesOnQuery(IQueryable query, params Expression>[] includeProperties) where TEntity : class, IEntity
{
// Return Applied Includes query
return (includeProperties.Aggregate(query, (current, include) => current.Include(include)));
}
Filter Method Call
public IEnumerable GetActiveShowStockProductListByProduct(int productId)
{
var foundedPStockroducts = Filter(
ent => ent.ProductId == productId && ent.IsActive,
ent => ent.StockProductPrices,
ent => ent.StockProductDepots,
ent => ent.StockProductSpecificationValues,
ent => ent.StockProductSpecificationValues.Select(spsv => spsv.SpecificationValue)
);
// Map foundedPStockroducts to showStockProductList
var showStockProductList = TypeAdapterFactory.Adapter.Adapt>(foundedPStockroducts).ToList();
return (showStockProductList);
}