示例#1
0
        /// <summary>
        /// 克隆出一个新的实体对象。
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var entity = _entityType.New <EntityObject>();

            entity.InitializeInstanceName((this.As <IEntityPersistentInstanceContainer>().InstanceName));
            entity.InitializeEnvironment(_environment);

            if (_entityType.IsNotCompiled())
            {
                foreach (var property in PropertyUnity.GetProperties(_entityType))
                {
                    var pv = GetValue(property);
                    entity.SetValue(property, pv);
                }
            }
            else
            {
                this.TryLockModifing(() =>
                {
                    InnerEntry.ForEach(k =>
                    {
                        var property = PropertyUnity.GetProperty(_entityType, k.Key);
                        if (property?.Info.IsPrimaryKey == true)
                        {
                            entity.InnerEntry.Initializate(k.Key, k.Value.GetCurrentValue());
                        }
                        else
                        {
                            entity.InnerEntry.Modify(k.Key, k.Value.GetCurrentValue());
                        }
                    });
                });
            }

            return(entity);
        }