Sql server 实体框架:按子表上的多个条件过滤
假设有两个表—Customers和CustomerConfiguration 客户包含ID、名称 CustomConfigurations包含CustomerID、Typeint、Valueint 我希望获得符合以下所有条件的所有客户: 具有类型为x且值为x1的customerconfiguration行 具有类型为y且值为y1的customerconfiguration行 具有类型为z且值为z1的customerconfiguration行 你明白了Sql server 实体框架:按子表上的多个条件过滤,sql-server,entity-framework,Sql Server,Entity Framework,假设有两个表—Customers和CustomerConfiguration 客户包含ID、名称 CustomConfigurations包含CustomerID、Typeint、Valueint 我希望获得符合以下所有条件的所有客户: 具有类型为x且值为x1的customerconfiguration行 具有类型为y且值为y1的customerconfiguration行 具有类型为z且值为z1的customerconfiguration行 你明白了 使用实体框架实现此类查询的最佳方法是什么?
使用实体框架实现此类查询的最佳方法是什么?我相信您的意思是:
dbContext.Customers.Where(cust =>
cust.CustomerConfigurations.Any(conf => conf.Type==x && conf.Value==x1) &&
cust.CustomerConfigurations.Any(conf => conf.Type==y && conf.Value==y1) &&
cust.CustomerConfigurations.Any(conf => conf.Type==z && conf.Value==z1));
这是最有效的查询方式吗?不幸的是,是的。考虑一下如何在SQL中实现这一点。