EF中的Where子句

时间:2014-09-30 08:19:19

标签: entity-framework

我们有4个实体:

  • Bills
  • BillDetails
  • Products
  • ProductGroups

我想做的是这样的事情

var qry = from bill in ctx.Bills
          join billDetail in ctx.BillDetails on bill.Id equal billDetail.Bill_Id
          join product in ctx.Products on billDetail.Product_Id equals product.Id
          join productGroup in ctx.ProductGroups 
                               on product.ProductGroup_Id equals productGroup.Id
          where 
               productGroup.Id == 113
          select bill;

问题是如果我们禁用延迟加载返回的bill dos不包含BillDetail实体, 我们必须明确地将其作为匿名对象返回。

有没有办法将它转换成这样的东西?

var qry = ctx.Bills
          .Include("BillDetails.Products.ProductGroup")
          .where(s=>s.BillDetails.Products.ProductGroup.Id == 113);

1 个答案:

答案 0 :(得分:0)

不是100%你需要什么,但这样的事情可能有效:

var qry = ctx.Bills
      .Include("BillDetails.Products.ProductGroup")
      .SelectMany(b => b.BillDetails)
      .Where(bd => bd.Product.ProductGroup.Id == 113);