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

深圳外贸企业网站建设为什么做电商网站

深圳外贸企业网站建设,为什么做电商网站,零基础怎么当程序员,晋城网站开发在实际更新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.zqtcl.cn/news/279337/

相关文章:

  • 网站建设和平面设计应用网站如何做
  • 自己做网站需要多少费用asa8.4 做网站映射
  • 商业网站 模板黑龙江省建设厅安全员考试
  • 网站新备案不能访问室内装修网站模板
  • 工程师报考网站wordpress设置视频图片不显示图片
  • 徐州网站建设公司排名成都住建平台
  • 用来备案企业网站国外免费外贸网站
  • 网页背景做的比较好的网站做一个企业网站价格
  • 免费制图网站县级门户网站建设的报告
  • 北京网站建设网怎么用手机做一个网站
  • 网站建设管理办法关于公司门户网站建设的议案
  • 网站开发入职转正申请书体验好的网站
  • 在线精品课程网站开发网站备案号怎么修改
  • 网站建设 风险百度热搜的含义
  • 怎样创作网站公司做网站 要准备哪些素材
  • 网站上的平面海报怎么做南阳企业做网站
  • 佛山公众平台网站推广多少钱wordpress如何调用分类目录
  • 网站推广应该注意什么信息发布平台推广
  • 官方网站案例做网站私活在哪接
  • 做网站滨州wordpress 不同域名
  • 找人做设计的网站广州做网站(信科网络)
  • 如何选择网站做站方向青之峰网站建设
  • 福州哪家网站制作设计高端还实惠设计logo的理念
  • 吉林市网站建设促销式软文案例
  • 三门峡市建设局网站网站开发费用是否资本化
  • 建设部网站官网 施工许可杭州萧山网站开发
  • 福建省建设资格注册管理中心网站竹子建站怎么样
  • 想做一个什么样的网站网站建设功能评价指标
  • 网站建设渠道合作友情链接是免费的吗
  • wordpress如何制作网站网站建设及推广方案ppt