/// <summary> /// 清除子对象集合 /// </summary> /// <param name="oldEntity">The old entity.</param> /// <param name="entityInfo">The entity information.</param> protected virtual void MakeSavedCore(Entity oldEntity, EntityMeta entityInfo) { foreach (var item in entityInfo.ChildrenProperties) { var mp = item.ManagedProperty as IListProperty; //如果是懒加载属性,并且没有加载数据时,不需要遍历此属性值 if (!oldEntity.FieldExists(mp)) { continue; } var children = oldEntity.GetProperty(mp) as EntityList; if (children == null) { continue; } //清除已删除数据 children.CastTo <EntityList>().DeletedList.Clear(); //所有子对象,都标记为已保存 for (int i = children.Count - 1; i >= 0; i--) { var child = children[i] as Entity; if (child.IsDirty || child.IsNew) { MakeSaved(child); } } } oldEntity.MarkSaved(); }
/// <summary> /// 根据实体状态来选择保存方法。 /// </summary> /// <param name="entity">The entity.</param> /// <param name="markSaved">是否当前正在保存最外层组合根对象。如果是,则应该在保存完成后,把整个组合对象状态清空。</param> /// <param name="withTreeChildren">是否需要同时处理树的子节点。</param> /// <exception cref="System.NotSupportedException"></exception> private void SubmitItem(Entity entity, bool markSaved, bool withTreeChildren) { //创建提交数据的参数。 var args = new SubmitArgs { Entity = entity, WithTreeChildren = withTreeChildren, Action = GetAction(entity) }; //提交更改。 _dataProvider.Submit(args); //保存完毕,修改实体的状态 switch (args.Action) { case SubmitAction.Delete: //在删除后,标记对象的状态到“新对象”。 entity.PersistenceStatus = PersistenceStatus.New; break; case SubmitAction.Update: case SubmitAction.Insert: case SubmitAction.ChildrenOnly: if (markSaved) { entity.MarkSaved(); } break; default: throw new NotSupportedException(); } }
/// <summary> /// 清除子对象集合 /// </summary> /// <param name="oldEntity">The old entity.</param> /// <param name="entityInfo">The entity information.</param> protected virtual void MakeSavedCore(Entity oldEntity, EntityMeta entityInfo) { foreach (var item in entityInfo.ChildrenProperties) { var mp = item.ManagedProperty as IListProperty; //如果是懒加载属性,并且没有加载数据时,不需要遍历此属性值 if (!oldEntity.FieldExists(mp)) continue; var children = oldEntity.GetProperty(mp) as EntityList; if (children == null) continue; //清除已删除数据 children.CastTo<EntityList>().DeletedList.Clear(); //所有子对象,都标记为已保存 for (int i = children.Count - 1; i >= 0; i--) { var child = children[i] as Entity; if (child.IsDirty || child.IsNew) MakeSaved(child); } } oldEntity.MarkSaved(); }