我正在尝试基于两个字段查找重复对象,但仅在第三个字段为空的情况下
ItemNumber, Name, Pricebook, Parent
Item1, A, B, <null>
Item2, A, B, Item1
Item3, A, B, <null>
Item4, A, B, Item1
Item5, A, B, Item2
所以在上述列表中,仅有两个重复的项目实际上是Item1和Item3。
var duplicateItemsList =
from i in items
group i by new { i.ItemNumber, i.Pricebook, i.Parent } into d
where d.Count() > 1
select new { ItemNumber = d.Key.ItemNumber, Pricebook = d.Key.Pricebook, Parent = d.Key.Parent, Count = d.Count() };
我遇到的问题是在Linq查询中检查空字段值。
在上述Linq查询之后,我只想得到一个包含重复的ItemNumber和Pricebook字段值的列表。
ItemNumber
分组而不是按Name
分组。 - BlachshmaItemNumber
是第一列(它包含“Item1”,“Item2”等),按照它进行分组将始终给出0个结果。 - Blachshma