当前位置: 首页 > news >正文

无极网络qq关键词排名优化

无极网络,qq关键词排名优化,电子商务营销的优势,中国建设银行手机银行家网站在实际更新Mongo对象时发现#xff0c;原有的更新代码无法更新复杂的数据类型对象。恰好看到张占岭老师有对该方法做相关的改进#xff0c;因此全抄了下来。 总的核心思想就是运用反射与递归#xff0c;对对象属性一层一层挖掘下去#xff0c;循环创建父类及之类的更新表达…在实际更新Mongo对象时发现原有的更新代码无法更新复杂的数据类型对象。恰好看到张占岭老师有对该方法做相关的改进因此全抄了下来。 总的核心思想就是运用反射与递归对对象属性一层一层挖掘下去循环创建父类及之类的更新表达式。 相关代码如下 #region 递归获取字段更新表达式private ListUpdateDefinitionT GetUpdateDefinitionsT(T entity) {var type typeof(T);var fieldList new ListUpdateDefinitionT();foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)){GenerateRecursionT(fieldList, property, property.GetValue(entity), entity, );}return fieldList; }private void GenerateRecursionTEntity(ListUpdateDefinitionTEntity fieldList,PropertyInfo property,object propertyValue,TEntity item,string father) {//复杂类型if (property.PropertyType.IsClass property.PropertyType ! typeof(string) propertyValue ! null){//集合if (typeof(IList).IsAssignableFrom(propertyValue.GetType())){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){for (int index 0; index arr.Count; index){foreach (var subInner in sub.PropertyType.GetProperties(BindingFlags.Instance | BindingFlags.Public)){if (string.IsNullOrWhiteSpace(father))GenerateRecursion(fieldList, subInner, subInner.GetValue(arr[index]), item, property.Name . index);elseGenerateRecursion(fieldList, subInner, subInner.GetValue(arr[index]), item, father . property.Name . index);}}}}}}//实体else{foreach (var sub in property.PropertyType.GetProperties(BindingFlags.Instance | BindingFlags.Public)){if (string.IsNullOrWhiteSpace(father))GenerateRecursion(fieldList, sub, sub.GetValue(propertyValue), item, property.Name);elseGenerateRecursion(fieldList, sub, sub.GetValue(propertyValue), item, father . property.Name);}}}//简单类型else{if (property.Name ! _id)//更新集中不能有实体键_id{if (string.IsNullOrWhiteSpace(father))fieldList.Add(BuildersTEntity.Update.Set(property.Name, propertyValue));elsefieldList.Add(BuildersTEntity.Update.Set(father . property.Name, propertyValue));}} }/// summary /// 构建Mongo的更新表达式 /// /summary /// param nameentity/param /// returns/returns private ListUpdateDefinitionT GeneratorMongoUpdateT(T item) {var fieldList new ListUpdateDefinitionT();foreach (var property in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public)){GenerateRecursionT(fieldList, property, property.GetValue(item), item, string.Empty);}return fieldList; }#endregion View Code   在实际应用过程中有几点要注意一下 1.在对象创建时就要将对象中的数组属性初始化否则在更新时无法插入子项。 public class Users : MongoObj {public Users() {Subs new ListSub();Spell new Listint();}public string ObjectId_id { get; set; }public string Name { get; set; }public string Sex { set; get; }public Listint Spell { get; set; }public ListSub Subs { get; set; } } 2.如果数组是一个复杂对象数据那么要给对象添加一个_id,并且在对象初始化时就给_id赋值。 public class Sub {public Sub() { _id MongoDB.Bson.ObjectId.GenerateNewId().ToString();}public string _id { get; set; }public string aa {get;set;}public string bb{get;set;} } 3.实际使用的时候发现无法对数组的子项做删除。   比如删除Subs中的第一个子项后再到mongo里面查询发现第一个子项仍然存在。    暂时还没有好的解决方法如果有涉及到数组子项的删除操作都是将整个对象删掉然后再重新插入简单粗暴。  转载于:https://www.cnblogs.com/nonkicat/p/5581726.html
http://www.yutouwan.com/news/115791/

相关文章:

  • 天猫商城入口如何搭建 seo网站
  • 怎么建设网站zy258h5个人页面制作
  • 定制高端网站建设如果你会建网站
  • 天水市秦州区作风建设年网站大气的公司名称大全
  • 东莞没有网站的公司网站建设 徐州
  • 网站建设具体详细过程网站制作东莞
  • 东莞数据线厂家东莞网站建设sem可以为网站建设做什么
  • 网站建设怎么跑业务手机网站qq登录插件
  • 织梦网站搜索怎么做网站开发投标文件
  • 大连企业网站网页设计及讲解多少钱
  • 电子通讯录网站建设北京今天的最新发布消息
  • 企业建设网站的主要目的淘宝下载安装
  • 网站规划与建设规划书超级外链自动发布工具
  • 北京网站建设免费网站一级a做爰在免费线看
  • 网站模板的缺点织梦汽车网站模板
  • 建设集团有限公司网站网站投入费用
  • 网站 做实名认证吗网站 手机 app
  • 内江市网站建设python 手机网站开发
  • 如何判断网站是否被k易语言 网站开发
  • 网站建设招标无锡建设网站成都
  • 上海网站排名团队logo设计在线生成免费影子
  • 西安知名的集团门户网站建设公司杭州网站建设培训班
  • 建设行业网站价格创建网店需要wordpress
  • 云浮新兴哪有做网站的社交网站 源码
  • 域名和网站建设实训报告广告优化师招聘
  • 企业免费建站网站网站开发 保修期
  • dede 网站源码wordpress4.8下载
  • asp做网站教程网站系统源代码
  • 有个虚拟服务器建设网站佛山网站建设工作
  • 网站建设是 口号上海优化外包