Example #1
0
 private void DeserializeList(Entity entity, IListProperty listProperty, JArray jArray)
 {
     var list = entity.GetLazyList(listProperty);
     var isNew = entity.PersistenceStatus == PersistenceStatus.New;
     if (isNew)
     {
         foreach (JObject jChild in jArray)
         {
             var child = list.GetRepository().New();
             DeserializeProperties(jChild, child);
             list.Add(child);
         }
     }
     else
     {
         //这里会发起查询,获取当前在数据库中的实体。
         for (int i = 0, c = jArray.Count; i < c; i++)
         {
             var jChild = jArray[i] as JObject;
             var child = FindOrCreate(list, jChild);
             DeserializeProperties(jChild, child);
         }
     }
 }
Example #2
0
        /// <summary>
        /// 删除所有组合子。
        /// 
        /// 子类重写此方法来实现新的删除逻辑。
        /// 注意,此方法只会在指定了 <see cref="EnableDeletingChildrenInMemory"/> 时,才会调用。
        /// </summary>
        protected virtual void DeleteChildren(Entity entity)
        {
            foreach (var mp in _repository.EntityMeta.ManagedProperties.GetNonReadOnlyCompiledProperties())
            {
                var listProperty = mp as IListProperty;
                if (listProperty != null && listProperty.HasManyType == HasManyType.Composition)
                {
                    //不论这个列表属性是否已经加载,都必须获取其所有的数据行,并标记为删除。
                    var list = entity.GetLazyList(listProperty);
                    if (list.Count > 0)
                    {
                        list.Clear();

                        //删除所有子。
                        SaveRecur(list, entity);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// 递归读取指定父对象中的所有子对象
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="batch">The batch.</param>
        private void ReadChildrenRecur(Entity entity, EntityBatch batch)
        {
            var childrenProperties = batch.Repository.EntityMeta.ChildrenProperties;

            //遍历所有子属性,读取孩子列表
            for (int i = 0, c = childrenProperties.Count; i < c; i++)
            {
                var cp = childrenProperties[i];
                var listProperty = cp.ManagedProperty as IListProperty;

                var children = entity.GetLazyList(listProperty);
                if (children.Count > 0)
                {
                    //所有孩子列表中的实体,都加入到对应的实体列表中。
                    //并递归读取孩子的孩子实体。
                    var entityType = children[0].GetType();
                    var childBatch = this.FindBatch(entityType);
                    ReadToBatchRecur(children, childBatch);
                }
            }
        }