我有一个通用的存储库,我试图在其中包含一个接受子表的变量列表来急切加载的函数。该函数看起来如此:
public IQueryable<T> FindBy(Expression<Func<T, bool>> predicate, params Expression<Func<T, object>>[] includeEntities)
{
IQueryable<T> query = this._dbSet.Where(e => !e.Deleted).Where(predicate);
foreach (var entity in includeEntities)
{
query.Include(entity);
}
return query;
}
它有效,但我关注object
引用。
使用这个功能:
var foundEntities = Repository.Entities.FindBy(i => i.Id == targetId, i => i.Orders, i => i.Invoices);
includeEntites
数组中传递的参数类型为System.Linq.Expressions.PropertyExpression
,遗憾的是它是一个内部类,所以我无法创建函数签名:
public IQueryable<T> FindBy(Expression<Func<T, bool>> predicate, params Expression<Func<T, System.Linq.Expressions.PropertyExpression>>[] includeEntities)
正如我所愿。有什么想法吗?