/// <summary> /// 加载当前集合中的节点元素。 /// </summary> public void Load() { if (!_loaded) { var repo = _owner.GetRepository(); var children = repo.GetByTreePId(_owner.Id); this.MergeFullTree(children.ToList()); } }
/// <summary> /// 通过引用属性、列表属性,递归搜索实体类中所涉及到的所有实体类型。 /// </summary> /// <param name="entity"></param> /// <returns></returns> private void DeepSearch(Entity entity) { _knownTypes = new List <Type>() { entity.GetType() }; DeepSearchRecur(entity.GetRepository()); }
protected override void Execute() { bool isNew = _diffEntity.IsNew; _diffEntity.GetRepository().Save(_diffEntity); this.NewId = _diffEntity.Id; //如果是新加的数据,则不需要传回客户端了。 if (isNew) { _diffEntity = null; } }
private static object GetRootId(Entity entity) { var parentPropertyMeta = entity.GetRepository().EntityMeta.FindParentReferenceProperty(); if (parentPropertyMeta == null) { return(entity.Id); } var refMP = parentPropertyMeta.ManagedProperty.CastTo <IRefEntityProperty>(); var parent = entity.GetRefEntity(refMP); return(GetRootId(parent)); }
/// <summary> /// 保存某个实体。 /// </summary> /// <param name="entity"></param> /// <param name="saveWay"></param> public static void Save(Entity entity, EntitySaveType saveWay) { var repo = entity.GetRepository(); if (saveWay == EntitySaveType.DiffSave && repo.DataPortalLocation == DataPortalLocation.Dynamic) { var isNew = entity.IsNew; var res = DiffSaveService.Execute(entity); if (isNew) { entity.Id = res.NewId; } } else { repo.Save(entity); } }
/// <summary> /// 尝试更新依赖指定实体的值的冗余属性的值。 /// </summary> /// <param name="entity">变更了值属性的实体。依赖该实体的所有冗余属性都需要被更新。</param> /// <param name="repository">实体对应的仓库。</param> public void UpdateRedundancies(Entity entity, IRepository repository) { if (repository == null) { repository = entity.GetRepository(); } //如果有一些在冗余属性路径中的属性的值改变了,则开始更新数据库的中的所有冗余字段的值。 Entity dbEntity = null; var propertiesInPath = repository.GetPropertiesInRedundancyPath(); for (int i = 0, c = propertiesInPath.Count; i < c; i++) { var property = propertiesInPath[i]; //如果只有一个属性,那么就是它变更引起的更新 //否则,需要从数据库获取原始值来对比检测具体哪些属性值变更,然后再发起冗余更新。 bool isChanged = c == 1; var refProperty = property as IRefIdProperty; if (refProperty != null) { if (!isChanged) { if (dbEntity == null) { dbEntity = ForceGetById(entity, repository); } var dbId = dbEntity.GetRefId(refProperty); var newId = entity.GetRefId(refProperty); isChanged = !object.Equals(dbId, newId); } if (isChanged) { foreach (var path in property.InRedundantPathes) { //如果这条路径中是直接把引用属性的值作为值属性进行冗余,那么同样要进行值属性更新操作。 if (path.ValueProperty.Property == property) { this.UpdateRedundancyByRefValue(entity, path, refProperty); } //如果是引用变更了,并且只有一个 RefPath,则不需要处理。 //因为这个已经在属性刚变更时的处理函数中实时处理过了。 else if (path.RefPathes.Count > 1) { this.UpdateRedundancyByIntermidateRef(entity, path, refProperty); } } } } else { var newValue = entity.GetProperty(property); if (!isChanged) { if (dbEntity == null) { dbEntity = ForceGetById(entity, repository); } var dbValue = dbEntity.GetProperty(property); isChanged = !object.Equals(dbValue, newValue); } if (isChanged) { foreach (var path in property.InRedundantPathes) { UpdateRedundancyByValue(entity, path, newValue); } } } } entity.UpdateRedundancies = false; }