相关实体的Where子句
我有一个通用存储库模式,我正在尝试加载基于 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,解决方案:< /strong>
代理机构由多个应用程序使用,他们需要能够启用/禁用每个应用程序。因此,我使用 AppAgency 表将该要求联系在一起。因为我不想每次引入新应用程序时都向 Agency
实体添加新列。
public IEnumerable<Agency> GetAllEnabledAgencies(int applicationId)
{
return _agencyRepository.GetMany(x => x.AppAgencies.Any(y => y.IsEnabled && y.FkApplicationId == applicationId));
}
I have a generic repository pattern and I'm trying to load a collection of Agencies based the FkApplicationId
and if it IsEnabled == true
My model looks something like this:
I thought this would be easy but I can't create a where
clause to filter the results. I can't see the properties of the AppAgencies
to write a condition, this is as far as I can get:
public IEnumerable<Agency> GetAllEnabledAgencies(int applicationId)
{
return _agencyRepository.GetMany(m => m.AppAgencies.//No Entity Properties are here);
}
From my repository base which is called from above:
public virtual IEnumerable<T> GetMany(Expression<Func<T, bool>> where)
{
return _dbSet.Where(where).ToList();
}
Thanks RPM1984, Solution:
Agencies are consumed by multiple applications, and they need the ability to enable/disable each one per application. So I was using the AppAgency table to tie together that req. because I don't want to have to add a new column to the Agency
entity every time a new application is introduced.
public IEnumerable<Agency> GetAllEnabledAgencies(int applicationId)
{
return _agencyRepository.GetMany(x => x.AppAgencies.Any(y => y.IsEnabled && y.FkApplicationId == applicationId));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有实体属性,因为
Agency
上的AppAgencies
属性是导航属性。我认为这就是您想要的:
英文:
如果你想:
将
任意
更改为全部
。There are no entity properties because the
AppAgencies
property onAgency
is a navigational property.I think this is what you want:
In English:
If you want:
Change
Any
toAll
.