中文字幕精品亚洲无线码二区,国产黄a三级三级三级看三级,亚洲七七久久桃花影院,丰满少妇被猛烈进入,国产小视频在线观看网站

Lind.DDD.Repositories.Mongo層介紹

回到目錄

之前已經發生了

大叔之前講過被倉儲化了的Mongodb,而在大叔開發了Lind.DDD之后,決定把這(zhe)個東西再(zai)搬到(dao)本框架的(de)(de)倉儲層來(lai),這(zhe)也是(shi)大勢(shi)所趨的(de)(de),畢竟mongodb是(shi)最像關系(xi)數(shu)據庫的(de)(de)NoSql,它(ta)的(de)(de)使用場景是(shi)其它(ta)nosql所不能及的(de)(de),這(zhe)點是(shi)毋庸置(zhi)疑的(de)(de)!

下面(mian)是大(da)叔總(zong)結的Mongodb文章(zhang)目錄,選自<大(da)叔Mongodb系列>

MongoDB學習筆記~環境搭建 (2015-03-30 10:34)

MongoDB學習筆記~MongoDBRepository倉儲的實現 (2015-04-08 12:00)

MongoDB學習筆記~ObjectId主鍵的設計 (2015-04-09 13:08)

MongoDB學習筆記~客戶端命令行的使用 (2015-04-10 13:40)

MongoDB學習筆記~索引提高查詢效率 (2015-04-10 15:35)

MongoDB學習筆記~為IMongoRepository接口添加分頁取集合的方法 (2015-04-11 22:13)

MongoDB學習筆記~Mongo集群和副本集 (2015-04-17 16:25)

MongoDB學習筆記~為IMongoRepository接口添加了排序和表達式樹,針對官方驅動 (2015-04-27 22:11)

MongoDB學習筆記~為IMongoRepository接口添加了增刪改方法,針對官方驅動 (2015-04-29 22:36)

MongoDB學習筆記~為IMongoRepository接口更新指定字段(2015-04-30 22:22)

MongoDB學習筆記~關于官方驅動集成IQueryable之后的一些事

MongoDB學習筆記~以匿名對象做為查詢參數,方便查詢子對象

MongoDB學習筆記~Update方法更新集合屬性后的怪問題

MongoDB學習筆記~批量插入方法的實現

MongoDB學習筆記~自己封裝的Curd操作(查詢集合對象屬性,更新集合對象)

MongoDB學習筆記~自己封裝的Curd操作(按需更新的先決條件)

MongoDB學習筆記~MongoDB實體中的值對象

MongoDB學習筆記~大叔框架實體更新支持N層嵌套~遞歸遞歸我愛你!

MongoDB學習筆記~大叔分享批量添加—批量更新—批量刪除

MongoDB學習筆記~MongoVUE對數據進行查詢,排序和按需顯示

MongoDB學習筆記~管道中的分組實現group+distinct

MongoDB學習筆記~官方驅動的原生Curd操作

MongoDB學習筆記~官方驅動嵌套數組對象的更新

MongoDB學習筆記~使用原生語句實現三層集合關系的更新

MongoDB學習筆記~數據結構與實體對象不一致時,它會怎么樣?

Lind.DDD里的倉儲模塊,Mongodb有一席之地

大叔的Mongodb倉儲結構

大(da)叔在設計(ji)mongodb查詢和更新(xin)時,使用到了遞歸(gui)

  /// <summary>
        /// 按需要更(geng)新的(de)構建者
        /// 遞歸構建Update操作(zuo)串
        /// </summary>
        /// <param name="fieldList"></param>
        /// <param name="property"></param>
        /// <param name="propertyValue"></param>
        /// <param name="item"></param>
        /// <param name="fatherValue"></param>
        /// <param name="father"></param>
        private void GenerateRecursionExpress(
          List<UpdateDefinition<TEntity>> fieldList,
          PropertyInfo property,
          object propertyValue,
          TEntity item,
          object fatherValue,
          string father)
        {
            //復雜類(lei)型
            if (property.PropertyType.IsClass && property.PropertyType != typeof(string) && propertyValue != null)
            {
                //集合
                if (typeof(IList).IsAssignableFrom(propertyValue.GetType()))
                {
                    var modifyIndex = 0;//要更新的(de)記錄(lu)索引(yin)
                    foreach (var sub in property.PropertyType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (sub.PropertyType.IsClass && sub.PropertyType != typeof(string))
                        {
                            var arr = propertyValue as IList;
                            if (arr != null && arr.Count > 0)
                            {

                                var oldValue = property.GetValue(fatherValue ?? item) as IList;
                                if (oldValue != null)
                                {
                                    for (int index = 0; index < arr.Count; index++)
                                    {
                                        for (modifyIndex = 0; modifyIndex < oldValue.Count; modifyIndex++)
                                            if (sub.PropertyType.GetProperty(EntityKey).GetValue(oldValue[modifyIndex]).ToString()
                                                == sub.PropertyType.GetProperty(EntityKey).GetValue(arr[index]).ToString())//比(bi)較_id是(shi)否相等
                                                break;
                                        foreach (var subInner in sub.PropertyType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                                        {
                                            if (string.IsNullOrWhiteSpace(father))
                                                GenerateRecursionExpress(fieldList, subInner, subInner.GetValue(arr[index]), item, arr[index], property.Name + "." + modifyIndex);
                                            else
                                                GenerateRecursionExpress(fieldList, subInner, subInner.GetValue(arr[index]), item, arr[index], father + "." + property.Name + "." + modifyIndex);
                                        }
                                    }
                                }

                            }
                        }
                    }
                }
                //實體
                else
                {
                    foreach (var sub in property.PropertyType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {

                        if (string.IsNullOrWhiteSpace(father))
                            GenerateRecursionExpress(fieldList, sub, sub.GetValue(propertyValue), item, property.GetValue(fatherValue), property.Name);
                        else
                            GenerateRecursionExpress(fieldList, sub, sub.GetValue(propertyValue), item, property.GetValue(fatherValue), father + "." + property.Name);
                    }
                }
            }
            //簡(jian)單類(lei)型
            else
            {
                if (property.Name != EntityKey)//更新(xin)集中不能有實體(ti)鍵_id
                {
                    if (string.IsNullOrWhiteSpace(father))
                        fieldList.Add(Builders<TEntity>.Update.Set(property.Name, propertyValue));
                    else
                        fieldList.Add(Builders<TEntity>.Update.Set(father + "." + property.Name, propertyValue));
                }
            }
        }

讓(rang)代碼去改變我們(men)(men)的(de)生活(huo),改變我們(men)(men)的(de)世界(jie)吧!

回到目錄

posted @ 2015-12-28 14:56  張占嶺  閱讀(1536)  評論(0)    收藏  舉報