示例#1
0
        private static void DeserializeList(Entity entity, IListProperty listProperty, JArray jArray)
        {
            var isNew = entity.PersistenceStatus == PersistenceStatus.New;

            if (isNew)
            {
                var list = entity.GetLazyList(listProperty);
                foreach (JObject jChild in jArray)
                {
                    var child = list.GetRepository().New();
                    DeserializeProperties(jChild, child);
                    list.Add(child);
                }
            }
            else
            {
                //这里会发起查询,获取当前在数据库中的实体。
                var list = entity.GetLazyList(listProperty);
                foreach (JObject jChild in jArray)
                {
                    Entity child = null;
                    JToken jId   = null;
                    if (jChild.TryGetValue(Entity.IdProperty.Name, StringComparison.OrdinalIgnoreCase, out jId))
                    {
                        child = list.Find((jId as JValue).Value);
                    }
                    if (child == null)
                    {
                        child = list.GetRepository().New();
                        list.Add(child);
                    }
                    DeserializeProperties(jChild, child);
                }
            }
        }
示例#2
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);
                }
            }
        }
示例#3
0
        private void DeserializeList(Entity entity, IListProperty listProperty, JArray jArray)
        {
            //构造 List 对象
            EntityList list = null;

            if (entity.FieldExists(listProperty) || entity.IsNew)
            {
                list = entity.GetLazyList(listProperty);
            }
            else
            {
                if (_creationMode == UpdatedEntityCreationMode.RequeryFromRepository)
                {
                    list = entity.GetLazyList(listProperty);
                }
                else
                {
                    var listRepository = RepositoryFactoryHost.Factory.FindByEntity(listProperty.ListEntityType);
                    list = listRepository.NewList();
                    entity.LoadProperty(listProperty, list);
                }
            }

            //反序列化其中的每一个元素。
            if (entity.IsNew)
            {
                var listRepository = list.GetRepository();
                foreach (JObject jChild in jArray)
                {
                    var child = listRepository.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);
                }
            }
        }
示例#4
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);
                }
            }
        }
示例#5
0
        private void DeepSearchRecur_Instance(Entity entity)
        {
            var values = entity.GetNonDefaultPropertyValues();

            foreach (var value in values)
            {
                var mp = value.Property as IProperty;
                switch (mp.Category)
                {
                case PropertyCategory.ReferenceEntity:
                    if (mp.GetMeta(entity).Serializable)
                    {
                        var refEntity = entity.GetRefEntity(mp as IRefEntityProperty);
                        AddEntityType(refEntity.GetType());
                        DeepSearchRecur_Instance(refEntity);
                    }
                    break;

                case PropertyCategory.List:
                    if (mp.GetMeta(entity).Serializable)
                    {
                        var list = entity.GetLazyList(mp as IListProperty);
                        for (int i = 0, c = list.Count; i < c; i++)
                        {
                            var child = list[i];
                            if (i == 0)
                            {
                                AddEntityType(child.GetType());
                            }
                            DeepSearchRecur_Instance(child);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
示例#6
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);
                    }
                }
            }
        }
示例#7
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);
         }
     }
 }
示例#8
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);
                }
            }
        }