示例#1
0
            internal void Clone(EntityTreeChildren source, CloneOptions options)
            {
                _loaded = source._loaded;
                if (_loaded)
                {
                    var srcNodes = source._nodes;
                    if (srcNodes != null)
                    {
                        _nodes = new List <Entity>();

                        var repo       = _owner.FindRepository();
                        var entityType = _owner.GetType();

                        for (int i = 0, c = srcNodes.Count; i < c; i++)
                        {
                            var src = srcNodes[i];

                            Entity entity = null;
                            if (repo != null)
                            {
                                entity = repo.New();
                            }
                            else
                            {
                                entity = Entity.New(entityType);
                            }

                            entity.Clone(src, options);

                            entity._treeParent = _owner;
                            _nodes.Add(entity);
                        }
                    }
                }
            }
示例#2
0
        /// <summary>
        /// 创建一个新的实体。
        ///
        /// 如果在已经获取 Repository 的场景下,使用本方法返回的实体会设置好内部的 Repository 属性,
        /// 这会使得 FindRepository、GetRepository 方法更加快速。
        /// </summary>
        /// <returns></returns>
        public Entity New()
        {
            var entity = Entity.New(this.EntityType);

            this.NotifyLoaded(entity);

            return(entity);
        }
示例#3
0
            //…… 其它查询方法的重写暂缓

            #endregion

            internal Entity FromRow(Entity row)
            {
                var entity = Entity.New(row.GetType());

                this.MemoryClone(row, entity);

                entity.PersistenceStatus = PersistenceStatus.Unchanged;

                return(entity);

                //return row;
            }
        /// <summary>
        /// 把一行数据转换为一个实体。
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        Entity IRepositoryInternal.ConvertRow(Entity row)
        {
            var entity = Entity.New(row.GetType());

            entity.PersistenceStatus = PersistenceStatus.Unchanged;

            //返回的子对象的属性只是简单的完全Copy参数data的数据。
            entity.Clone(row, CloneOptions.ReadDbRow());

            this.NotifyLoaded(entity);

            return(entity);
        }
示例#5
0
        /// <summary>
        /// 把一行数据转换为一个实体。
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        Entity IRepositoryInternal.ConvertRow(Entity row)
        {
            var entity = Entity.New(row.GetType());

            //返回的子对象的属性只是简单的完全Copy参数data的数据。
            var opt = CloneOptions.ReadDbRow();

            opt.Method = CloneValueMethod.LoadProperty;
            entity.Clone(row, opt);
            entity.PersistenceStatus = PersistenceStatus.Unchanged;

            this.NotifyLoaded(entity);

            return(entity);
        }
示例#6
0
            internal void Clone(EntityTreeChildren source, CloneOptions options)
            {
                _loaded = source._loaded;
                if (_loaded)
                {
                    var srcNodes = source._nodes;
                    if (srcNodes != null)
                    {
                        _nodes = new List <Entity>();

                        var repo       = _owner.FindRepository();
                        var entityType = _owner.GetType();

                        for (int i = 0, c = srcNodes.Count; i < c; i++)
                        {
                            var src = srcNodes[i];

                            Entity entity = null;
                            if (repo != null)
                            {
                                entity = repo.New();
                            }
                            else
                            {
                                entity = Entity.New(entityType);
                            }

                            /*修复Entitylist使用TreeChildren属性Clone时TreeIndex错误问题
                             *原因是TreeChildren中实体Clone时会TreePId改变触发OnTreePIdChanged事件,
                             * OnTreePIdChanged事件中会处理entity._treeParent为空并且
                             * _treeParent.Id不等于新的克隆值时,需要重新设置TreeParent值
                             * 导致设置TreeIndex错误
                             * 所以需要entity克隆前设置_treeParent的值为 source._owner
                             */

                            entity._treeParent = source._owner;

                            entity.Clone(src, options);

                            entity._treeParent = _owner;
                            _nodes.Add(entity);
                        }
                    }
                }
            }