婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > Queryable.Union 方法實(shí)現(xiàn)json格式的字符串合并的具體實(shí)例

Queryable.Union 方法實(shí)現(xiàn)json格式的字符串合并的具體實(shí)例

熱門標(biāo)簽:怎么給超市做地圖標(biāo)注入駐店 外呼系統(tǒng)代理品牌 手機(jī)地圖標(biāo)注如何刪除 巫師3為什么地圖標(biāo)注的財(cái)寶沒(méi)有 世紀(jì)佳緣地圖標(biāo)注怎么去掉 辦理400電話證件 寧波自動(dòng)外呼系統(tǒng)代理 十堰正規(guī)電銷機(jī)器人系統(tǒng) 外呼系統(tǒng)費(fèi)用一年

1.在數(shù)據(jù)庫(kù)中以json字符串格式保存,如:[{"name":"張三","time":"8.592","area":"27.27033","conc":"4.12136"},{"name":"李四","time":"9.100","area":"56.21229","conc":"4.57692"}]

2.添加新內(nèi)容后合并不相同的數(shù)據(jù)。如果name相同,以最新的數(shù)據(jù)替換原來(lái)的數(shù)據(jù)。

如:數(shù)據(jù)庫(kù)中原保存的數(shù)據(jù)是[{"name":"張三","time":"8.592","area":"27.27033","conc":"4.12136"},{"name":"李四","time":"9.100","area":"56.21229","conc":"4.57692"}]

新加的數(shù)據(jù)為[{"name":"張三","time":"12","area":"27.70533","conc":"4.12136"},{"name":"王五","time":"4","area":"77","conc":"8.788"}]

 則替換后的數(shù)據(jù)為[{"name":"張三","time":"12","area":"27.70533","conc":"4.12136"},{"name":"王五","time":"4","area":"77","conc":"8.788"},{"name":"李四","time":"9.100","area":"56.21229","conc":"4.57692"}]

代碼如下:

復(fù)制代碼 代碼如下:

public void InsertOrUpdateOnlyItem(ListtblLims_Ana_LE_Import_Common> listLe)
        {
            var listLeInsert = new ListtblLims_Ana_LE_Import_Common>();
            var listLeUpdate = new ListtblLims_Ana_LE_Import_Common>();
            foreach (var le in listLe)
            {
                tblLims_Ana_LE_Import_Common model = le;
                var own = CurrentRepository.Find(a => a.fldTaskID == model.fldTaskID
                a.fldBizCatID == model.fldBizCatID
                a.fldItemCode == model.fldItemCode
                a.fldNumber == model.fldNumber
                a.fldSampleCode == model.fldSampleCode);
                if (own != null)
                {
                    var ser = new JavaScriptSerializer();

                    var listown = ser.DeserializeListDictionarystring, string>>>(own.fldImportData);  //原數(shù)據(jù)
                    var listmodel = ser.DeserializeListDictionarystring, string>>>(model.fldImportData); //新數(shù)據(jù)
                    IEqualityComparerDictionarystring, string>> ec = new EntityComparer();   //自定義的比較類
                    own.fldImportData = ser.Serialize(listmodel.Union(listown, ec));  //合并數(shù)據(jù)


                    listLeUpdate.Add(own);
                }
                else
                {
                    listLeInsert.Add(model);
                }
            }
            CurrentRepository.UpdateAll(listLeUpdate);
            CurrentRepository.InsertAll(listLeInsert);
            CurrentRepository.Save();
        }


tblLims_Ana_LE_Import_Common 為數(shù)據(jù)庫(kù)中存數(shù)據(jù)的表

Union() 方法中用到的自定義比較類:

復(fù)制代碼 代碼如下:

/// summary>
    /// 自定義比較類
    /// /summary>
    public class EntityComparer : IEqualityComparerDictionarystring, string>>
    {
        public bool Equals(Dictionarystring, string> x, Dictionarystring, string> y)
        {
            if (ReferenceEquals(x, y)) return true;

            if (ReferenceEquals(x, null) || ReferenceEquals(y, null))
                return false;

            return x["name"] == y["name"];  //如果名稱相同就不追加
        }

        public int GetHashCode(Dictionarystring, string> obj)
        {
            if (ReferenceEquals(obj, null)) return 0;
            int hashName = obj["name"] == null ? 0 : obj["name"].GetHashCode();
            int hashCode = obj["name"] == null ? 0 : obj["name"].GetHashCode();
            return hashName ^ hashCode;
        }
    }

您可能感興趣的文章:
  • JS實(shí)現(xiàn)合并json對(duì)象的方法
  • JavaScript簡(jiǎn)單實(shí)現(xiàn)合并兩個(gè)Json對(duì)象的方法示例
  • JavaScript實(shí)現(xiàn)JSON合并操作示例【遞歸深度合并】
  • js根據(jù)json數(shù)據(jù)中的某一個(gè)屬性來(lái)給數(shù)據(jù)分組的方法
  • Javascript中JSON數(shù)據(jù)分組優(yōu)化實(shí)踐及JS操作JSON總結(jié)
  • JS遍歷JSON數(shù)組及獲取JSON數(shù)組長(zhǎng)度操作示例【測(cè)試可用】
  • JavaScript實(shí)現(xiàn)構(gòu)造json數(shù)組的方法分析
  • JS實(shí)現(xiàn)鍵值對(duì)遍歷json數(shù)組功能示例
  • JavaScript數(shù)組,JSON對(duì)象實(shí)現(xiàn)動(dòng)態(tài)添加、修改、刪除功能示例
  • js實(shí)現(xiàn)json數(shù)組分組合并操作示例

標(biāo)簽:景德鎮(zhèn) 嘉興 牡丹江 泰州 山西 通遼 天門

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Queryable.Union 方法實(shí)現(xiàn)json格式的字符串合并的具體實(shí)例》,本文關(guān)鍵詞  Queryable.Union,方法,實(shí)現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Queryable.Union 方法實(shí)現(xiàn)json格式的字符串合并的具體實(shí)例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Queryable.Union 方法實(shí)現(xiàn)json格式的字符串合并的具體實(shí)例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 永修县| 彰化县| 虞城县| 航空| 陇川县| 文化| 彩票| 本溪市| 上高县| 阳高县| 吉林省| 嘉祥县| 巨鹿县| 四川省| 石家庄市| 漳浦县| 兴义市| 澳门| 武定县| 石景山区| 兴宁市| 元江| 崇左市| 云安县| 九江市| 阿鲁科尔沁旗| 浙江省| 兴和县| 凤翔县| 南澳县| 杭州市| 屏山县| 红安县| 锡林浩特市| 怀来县| 海盐县| 许昌县| 泰安市| 锦屏县| 南澳县| 繁昌县|