相关实体的Where子句

发布于 2024-11-30 18:46:37 字数 1068 浏览 1 评论 0原文

我有一个通用存储库模式,我正在尝试加载基于 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:
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南巷近海 2024-12-07 18:46:37

没有实体属性,因为 Agency 上的 AppAgencies 属性是导航属性。

我认为这就是您想要的:

public IEnumerable<Agency> GetAllEnabledAgencies(int applicationId)
{
    return _agencyRepository.GetMany(x => x.AppAgencies.Any(y => y.IsEnabled));
}

英文:

获取所有启用了至少一个 AppAgency 的代理机构。

如果你想:

获取所有启用了所有 AppAgency 的代理机构。

任意更改为全部

There are no entity properties because the AppAgencies property on Agency is a navigational property.

I think this is what you want:

public IEnumerable<Agency> GetAllEnabledAgencies(int applicationId)
{
    return _agencyRepository.GetMany(x => x.AppAgencies.Any(y => y.IsEnabled));
}

In English:

Get all Agencies, where at least one AppAgency is enabled.

If you want:

Get all Agencies, where all AppAgency is enabled.

Change Any to All.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文