• 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;
            }
        }
  • 相关阅读:
    C盘的可用空间忽大忽小
    安装软件时不能指定软件的安装目录
    MySQL安装排坑
    Butterfly主题目录生成不了问题
    apache+php安装配置的各种问题
    环境变量配置不成功
    http模块
    Node.js
    Spring Boot入门
    代码优化笔记
  • 原文地址:https://www.cnblogs.com/Beau/p/4450967.html
Copyright © 2020-2023  润新知