Linq 取差集 交集等
string goodsList = context.Request.Form["goodsList"]; if (!string.IsNullOrEmpty(goodsList)) { //同步过来物品数据,删除后修改 List<FSTP_ADPMS_SoakGoodsInfo> goodsLst = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FSTP_ADPMS_SoakGoodsInfo>>(goodsList); if(goodsLst.Count != 0) { int OrgID = goodsLst[0].OrganiseUnitID; QueryBuilder queryBuilder = new QueryBuilder(); queryBuilder.AddFilter(FSTP_ADPMS_SoakGoodsInfo.FSTP_ADPMS_SOAKGOODS_TABLE, FSTP_ADPMS_SoakGoodsInfo.ORGANISEUNITID_FIELD, "=", OrgID); //数据库中存在数据 List<FSTP_ADPMS_SoakGoodsInfo> oldLst = new FSTP_ADPMS_SoakGoodsBLL().GetModelList(queryBuilder); //添加数据 List<FSTP_ADPMS_SoakGoodsInfo> insertLst = goodsLst.Except(oldLst, new SoakGoodsInfoCompare()).ToList(); //修改数据 List<FSTP_ADPMS_SoakGoodsInfo> updateLst = goodsLst.Intersect(oldLst, new SoakGoodsInfoCompare()).ToList(); if (Goodsbll.Add(insertLst, updateLst) != "0") { context.Response.Write(" Resule->OK"); } } } //物品对比类 public class SoakGoodsInfoCompare : IEqualityComparer<FSTP_ADPMS_SoakGoodsInfo> { public bool Equals(FSTP_ADPMS_SoakGoodsInfo x, FSTP_ADPMS_SoakGoodsInfo y) { return x.ID == y.ID; } public int GetHashCode(FSTP_ADPMS_SoakGoodsInfo obj) { return 0; } }