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)) { /*违反多字段唯一时,提示信息处理*/ }
posted @ 2014-10-29 18:54  hornet_team  阅读(368)  评论(0编辑  收藏  举报