我想根据另一个属性
为以下查询添加一个条件例如“和a.City = b.City”。我该怎么办呢。
当前查询
var result = firstCollection.Join(secondCollection,
a => a.CustomerId,
b => b.CustomerId, //TO ADD "and a.City=b.City"
GetDifferences)
.SelectMany(x => x)
.Where(x => x != null).ToList();
在sql中我会这样做:
Select * from firstCollection a
INNER JOIN secondCollection B on a.CustomerId=b.CustomerId and a.city=b.city
非常感谢你的建议
答案 0 :(得分:1)
使用匿名类型:
var result = firstCollection.Join(secondCollection,
a => new { a.CustomerId, a.City }
b => new { b.CustomerId, b.City },
GetDifferences)
.SelectMany(x => x)
.Where(x => x != null).ToList();