我正在尝试执行一个组,然后执行一个 distinct 来验证一组列是否仅映射到其他列。例如,在下面的数据集中
Brand Product Location Customer Demand
Box A Chicago Chicago 10
Box B Chicago Milwaukee 20
Cart C Madison Milwaukee 10
Cart D Chicago Milwaukee 15
产品 A、B、C 有效。但 D 无效,因为存在以芝加哥为位置、密尔沃基为客户的产品 B。我正在尝试构建一个 LINQ 查询来获取异常记录并遇到一些麻烦。我很确定我的查询过于复杂。
var vDuplicateSupplierLitho = from p in vRecords
group p by new
{
Location = p["Location"].Cast<string>(),
Customer = p["Customer"].Cast<string>()
} into grp
select new
{
Location = grp.Key.Location,
Customer = grp.Key.Customer,
Products = from a in grp
group a by new { Product = a["Product"].Cast<string>() } into apngrp
where apngrp.Count() > 1 && apngrp.Select(a => a["Product"]).Distinct().Count() > 1
from NonUniqueRecord in apngrp
select new
{
Product = apngrp.key.Product,
Location = g.key.Location,
Customer = g.key.Customer
Demand = NonUniqueRecord["Demand"]
}
};
谢谢。