首页 > 代码库 > Linq To Object多字段组合唯一校验

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)) { /*违反多字段唯一时,提示信息处理*/}

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