本文共 4324 字,大约阅读时间需要 14 分钟。
,而在大叔开发了Lind.DDD之后,决定把这个东西再搬到本框架的仓储层来,这也是大势所趋的,毕竟mongodb是最像关系数据库的NoSql,它的使用场景是其它nosql所不能及的,这点是毋庸置疑的!
下面是大叔总结的Mongodb文章目录,选自<大叔Mongodb系列>
(2015-03-30 10:34)
(2015-04-08 12:00)
(2015-04-09 13:08)
(2015-04-10 13:40)
(2015-04-10 15:35)
(2015-04-11 22:13)
(2015-04-17 16:25)
(2015-04-27 22:11)
(2015-04-29 22:36)
(2015-04-30 22:22)
大叔在设计mongodb查询和更新时,使用到了递归
////// 按需要更新的构建者 /// 递归构建Update操作串 /// /// /// /// /// /// /// private void GenerateRecursionExpress( List> fieldList, PropertyInfo property, object propertyValue, TEntity item, object fatherValue, string father) { //复杂类型 if (property.PropertyType.IsClass && property.PropertyType != typeof(string) && propertyValue != null) { //集合 if (typeof(IList).IsAssignableFrom(propertyValue.GetType())) { var modifyIndex = 0;//要更新的记录索引 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())//比较_id是否相等 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); } } } //简单类型 else { if (property.Name != EntityKey)//更新集中不能有实体键_id { if (string.IsNullOrWhiteSpace(father)) fieldList.Add(Builders .Update.Set(property.Name, propertyValue)); else fieldList.Add(Builders .Update.Set(father + "." + property.Name, propertyValue)); } } }
让代码去改变我们的生活,改变我们的世界吧!
本文转自博客园张占岭(仓储大叔)的博客,原文链接:,如需转载请自行联系原博主。