首页 > 解决方案 > 如何使用 LINQ 将表值与对象列表的属性值进行比较?

问题描述

鉴于这些课程,

public class Foo
{   
    ...  

    public IList<Bar> BarList{ get; set; }
}

public class Bar
{
    ...

    public int Property{ get; set; }
}

当 Property 是列表中对象的属性时,如何使用 LINQ 创建一个查询来过滤 Property 值的匹配项?

即,我想返回OtherTable 的Property 列的值与Foo.BarList 中存在的任何Property 值匹配的所有记录。就像是

var result = db.MainTable.Include(m => m.OtherTable.Where(o => o.Property == {{Foo.BarList.Property}}) ...rest of query

谢谢你。

标签: c#asp.netentity-frameworklinq

解决方案


推荐阅读