c# - 有没有办法在实体框架中使用来自不同实体的多个过滤器参数?
问题描述
我正在创建一个事件管理 asp.net 核心应用程序,我的客户实体通过多对多的关系与不同的实体相关。知道我想根据事件名称和主要类别名称实体过滤我的客户。
这是我的实体
顾客
public class Customer
{
public int Id {get; set;}enter code here
public string Name { get; set; }
public IList<CustomerEvent> CustomerEvents { get; set; }
public IList<CustomerMainCategory> CustomerMainCategories { get; set; }
}
事件
public class Event
{
public int Id { get; set; }
public string EventName { get; set; }
public IList<CustomerEvent> CustomerEvents { get; set; }
}
客户事件
public Class CustomerEvent
{
public int CustomerId { get; set; }
public Customer Customer { get; set; }
public int EventId { get; set; }
public Event Event { get; set; }
}
主要类别
public class MainCategory
{
public int Id { get; set; }
public string MainCategoryName { get; set; }
public IList<CustomerMainCategory> CustomerMainCategories { get; set; }
}
客户主要类别
public class CustomerMainCategory
{
public int CustomerId { get; set; }
public Customer Customer { get; set; }
public int MainCategoryId { get; set; }
public MainCategory MainCategory { get; set; }
}
我想过滤在指定事件中具有相同主要类别的客户。
先感谢您!!
解决方案
像这样的东西?(未测试)
db.Customers.Where(
c => c.CustomerEvents.Any(ce => ce.Event.Id == x)
&& c.CustomerMainCategories.Any(mc => mc.MainCategory.Id == y)
).ToList();
推荐阅读
- vb.net - SQL Server 和 VB.Net 已经有一个与此连接关联的开放数据读取器
- c# - 如何在 C# 控制台应用程序中获取当前 Windows 用户名?
- objective-c - 音频没有在 UIWebView 中使用目标 C 播放
- vuetify.js - 如何提取一个
- android - 由于moxy,项目没有编译
- wordpress - 在 Wordpress 中发布帖子后如何获得永久链接
- c# - Azure VM 上的双向 SSL 证书交换
- ios - 无法将实时数据库代码转换为 Firestore 代码
- json - 我想在 swift 中为 post 参数创建一个 API JSON 结构
- ffmpeg - mp3 + jpg 使用 ffmpeg 后没有音频