C# 添加将linq连接到对象c的条件#

C# 添加将linq连接到对象c的条件#,c#,linq,C#,Linq,我想根据另一个属性向下面的查询添加一个条件 “a.City=b.City”,我该怎么做呢 当前查询 var result = firstCollection.Join(secondCollection, a => a.CustomerId, b => b.CustomerId, //TO ADD "and a.City=b.City"

我想根据另一个属性向下面的查询添加一个条件

“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
非常感谢您的建议

使用匿名类型:

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();

谢谢你的帮助。customerId上的匹配如何,但我想知道城市上不匹配的所有记录。基本上,给我所有具有相同customerId但城市不匹配的记录。对此表示抱歉。我刚想到我需要这样做