实体框架:按子表上的多个条件过滤

时间:2014-10-29 11:33:59

标签: sql-server entity-framework

假设有两个表 - Customers和CustomerConfigurations。

客户包含ID,NAME

CustomConfigurations包含CustomerID,Type(int),Value(int)

我想让所有客户满足以下所有条件:

  1. 具有type = x和value = x1

  2. 的客户配置行
  3. 具有type = y和value = y1

  4. 的customerconfiguration行
  5. 具有type = z和value = z1

  6. 的客户配置行

    你明白了。

    使用实体框架实现此类查询的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

我相信你的意思是这样的:

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));
相关问题