【问题标题】:Linq to sql select records based on child recordsLinq to sql 根据子记录选择记录
【发布时间】:2011-10-22 01:55:14
【问题描述】:

我在尝试使此声明生效时遇到问题。我正在尝试根据一对多子关系表过滤父记录集。我收到无法将 lambda 表达式转换为委托类型的错误。如果可能的话,我想继续使用 Linq 解决方案。

result = db.ParentTable.Where(r => r.ChildTable.Where(c => c.ChildField == value));

【问题讨论】:

    标签: c# linq-to-sql


    【解决方案1】:

    不确定我是否理解您的需求,但也许就是这样:

    db.ParentTable.Where(r => r.ChildTable.Any(c => c.ChildField == value));
    

    【讨论】:

      【解决方案2】:

      使用查询语法:

      result = from parent in db.ParentTable
               from child in parent.ChildTable
               where child.ChildField == value
               select parent;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多