【问题标题】:Using ObjectQuery Include and using a nested where clause使用 ObjectQuery Include 并使用嵌套的 where 子句
【发布时间】:2009-03-13 21:48:52
【问题描述】:

使用实体框架,我试图用订单详细信息找回客户,但我想过滤掉那些处于活动状态的订单。

Customer 是我们的 EntityObject,它有一个 Order EntityObjects 的集合。 CustomerDetails 是我们的 ObjectContext。

下面的代码将附加所有订单,但我想过滤并仅附加那些处于活动状态的订单。 (Order.active == true)。我怎样才能做到这一点?

我知道 Include 构建了一个嵌套查询语句(我可以通过使用 .ToTraceString() 来观察。)我希望将 Where 子句附加到这个嵌套的 select 语句或 Include 中。

            Customer cust;
        CustomerDetails custTable = new CustomerDetails();


        cust = custTable.Customer
            .Where("it.cust_id = " + id)
            .Include("Order")  // But we only want Order.active == true!!!
            .ToList().First();

【问题讨论】:

    标签: entity-framework nested


    【解决方案1】:

    未经测试,但可能有效?

    var temp = custTable.Customer.Where("it.cust_id = " + id).Include("Order");
    cust = (from t in temp 
            where t.Order.active == true 
            select t).ToList().First();
    

    【讨论】:

      猜你喜欢
      • 2016-12-31
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 2013-05-08
      相关资源
      最近更新 更多