Linq To Object多字段组合唯一校验

1.第一种方式
if(partsSalesOrderTypes.GroupBy(entity => new {
entity.Name,
entity.Code
}).Any(array => array.Count() > 1)) {
/*违反多字段唯一时,提示信息处理*/
return;
}
2.第二种方式
var groupPrice = from price in this.PartsSpecialTreatyPrices
group price by new {
price.DealerId, //分组字段
price.PartsSalesCategoryId, //分组字段
price.SparePartId //分组字段
}
into groups
select new {
count = groups.Count(),
key = groups.Key

};
if(groupPrice.Any(group => group.count > 1)) {
/*违反多字段唯一时,提示信息处理*/
}

原文地址 https://www.cnblogs.com/hornet/p/4060290.html

原文地址:https://www.cnblogs.com/suizhikuo/p/11084337.html