如何从Linq中选择多个列表?

时间:2017-08-04 10:22:07

标签: c# class linq-to-entities

我有这个sql select:

select a.*
from a inner join b on (a.col1=b.col1 and a.col2=b.col2)

让我们假设a,b现在是lists.Can你能帮我在带有lambda表达式的c#,Linq中编写这个select吗?

2 个答案:

答案 0 :(得分:1)

您正在寻找的方法是     Enumerable.Join<TOuter, TInner, TKey, TResult>, 见https://msdn.microsoft.com/en-us/library/bb534675(v=vs.110).aspx

答案 1 :(得分:0)

from a inner join b on (a.col1=b.col1 and a.col2=b.col2)

可以像这样转换成LINQ:

a.Join(b, aItem => aItem.col2, bItem => bItem.col2,
(aItem, bItem) => new { aItem = aItem, bItem = bItem, col2 = aItem.col2);