gpt4 book ai didi

c# - 添加条件以将 linq 加入对象 c#

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:06 25 4
gpt4 key购买 nike

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

例如“and 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();

关于c# - 添加条件以将 linq 加入对象 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33796149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com