如何使用LINQ将表值与对象列表的属性值进行比较?

时间:2018-05-25 19:15:06

标签: c# asp.net entity-framework 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中存在的任何属性值相匹配。像

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

谢谢。

0 个答案:

没有答案