【发布时间】:2011-11-01 13:31:10
【问题描述】:
我有一个通用存储库模式,我正在尝试加载基于 FkApplicationId 的代理集合,如果它是 IsEnabled == true
我的模型看起来像这样:
我认为这很容易,但我无法创建 where 子句来过滤结果。我看不到 AppAgencies 的属性来写条件,这是我所能得到的:
public IEnumerable<Agency> GetAllEnabledAgencies(int applicationId)
{
return _agencyRepository.GetMany(m => m.AppAgencies.//No Entity Properties are here);
}
从上面调用的我的存储库库中:
public virtual IEnumerable<T> GetMany(Expression<Func<T, bool>> where)
{
return _dbSet.Where(where).ToList();
}
感谢 RPM1984,解决方案:
代理由多个应用程序使用,它们需要能够启用/禁用每个应用程序中的每一个。因此,我使用 AppAgency 表将该请求联系在一起。因为我不想每次引入新应用程序时都必须向Agency 实体添加新列。
public IEnumerable<Agency> GetAllEnabledAgencies(int applicationId)
{
return _agencyRepository.GetMany(x => x.AppAgencies.Any(y => y.IsEnabled && y.FkApplicationId == applicationId));
}
【问题讨论】:
标签: entity-framework repository-pattern poco