Esempio n. 1
0
        //internal static DataTable Create(DataTable root, DataTable master, Type objectType, DataTableType tableType, IDataField memberField)
        //{
        //    var objectFields = DataModel.GetObjectFields(objectType, master.IsSnapshot);
        //    return Create(root, master, objectType, master.IsSnapshot, tableType, objectFields, memberField);
        //}


        internal static DataTable CreateSnapshot(Type objectType, IEnumerable <IDataField> objectFields)
        {
            if (!DomainObject.IsAggregateRoot(objectType))
            {
                throw new SnapshotTargetException();
            }
            DataTableType tableType = DataTableType.AggregateRoot;

            return(Create(null, null, objectType, true, tableType, objectFields, null));
        }
Esempio n. 2
0
        internal static DataTable Create(Type objectType, IEnumerable <IDataField> objectFields)
        {
            DataTableType tableType = DataTableType.AggregateRoot;

            if (DomainObject.IsAggregateRoot(objectType))
            {
                tableType = DataTableType.AggregateRoot;
                return(Create(null, null, objectType, false, tableType, objectFields, null));
            }
            throw new DomainDrivenException(string.Format(Strings.PersistentObjectError, objectType.FullName));
        }
Esempio n. 3
0
        internal static DataModel CreateNew(Type objectType)
        {
            var objectFields = GetObjectFields(objectType, false);
            var root         = DataTable.Create(objectType, objectFields);

            var snapshotObjectFields = GetObjectFields(objectType, true);
            var snapshot             = DomainObject.IsAggregateRoot(objectType)
                            ? DataTable.CreateSnapshot(objectType, snapshotObjectFields)
                            : null;

            return(new DataModel(objectType, root, snapshot));
        }
Esempio n. 4
0
        /// <summary>
        /// 获取集合类型的数据字段
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="propertyType"></param>
        /// <returns></returns>
        private bool TryGetListField(PropertyRepositoryAttribute attribute, bool isSnapshot, ref IDataField result)
        {
            var elementType = attribute.GetElementType();

            if (DomainObject.IsValueObject(elementType))
            {
                //值对象
                var field = new ValueObjectListField(attribute);
                //当值对象A引用了值对象A时,会造成死循环
                //var mapper = DataMapperFactory.Create(elementType);
                //var childs = mapper.GetObjectFields(elementType, isSnapshot);
                //field.AddChilds(childs);

                result = field;
                return(true);
            }
            else if (DomainObject.IsAggregateRoot(elementType))
            {
                //引用了根对象
                var field = new AggregateRootListField(attribute);
                result = field;
                return(true);
            }
            else if (DomainObject.IsEntityObject(elementType))
            {
                //引用了内部实体对象
                var field = new EntityObjectListField(attribute);
                //当成员对象A引用了成员对象A时,会造成死循环
                //var mapper = DataMapperFactory.Create(elementType);
                //var childs = mapper.GetObjectFields(elementType, isSnapshot);
                //field.AddChilds(childs);

                result = field;
                return(true);
            }
            else if (elementType.IsList())
            {
                throw new DomainDesignException(Strings.NestedCollection);
            }
            else
            {
                //值集合
                var field = new ValueListField(attribute);
                result = field;
                return(true);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 获取集合类型的数据字段
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="propertyType"></param>
        /// <returns></returns>
        private static bool TryGetListField(PropertyRepositoryAttribute attribute, bool isSnapshot, ref IDataField result)
        {
            var elementType = attribute.PropertyType.ResolveElementType();

            if (DomainObject.IsValueObject(elementType))
            {
                //值对象
                var field  = new ValueObjectListField(attribute);
                var childs = GetObjectFields(elementType, isSnapshot);
                field.AddChilds(childs);

                result = field;
                return(true);
            }
            else if (DomainObject.IsAggregateRoot(elementType))
            {
                //引用了根对象
                var field = new AggregateRootListField(attribute);
                result = field;
                return(true);
            }
            else if (DomainObject.IsEntityObject(elementType))
            {
                //引用了内部实体对象
                var field  = new EntityObjectListField(attribute);
                var childs = GetObjectFields(elementType, isSnapshot);
                field.AddChilds(childs);

                result = field;
                return(true);
            }
            else if (IsList(elementType))
            {
                throw new DomainDesignException(Strings.NestedCollection);
            }
            else
            {
                //值集合
                var field = new ValueListField(attribute);
                result = field;
                return(true);
            }
        }
Esempio n. 6
0
        internal static DataModel CreateNew(Type objectType)
        {
            var mapper = DataMapperFactory.Create(objectType);

            var objectFields = mapper.GetObjectFields(objectType, false);
            var root         = DataTable.Create(objectType, objectFields);

            DataTable snapshot = null;

            if (DomainObject.IsAggregateRoot(objectType))
            {
                var tip = ObjectRepositoryAttribute.GetTip(objectType, true);
                if (tip.Snapshot)
                {
                    var snapshotObjectFields = mapper.GetObjectFields(objectType, true);
                    snapshot = DataTable.CreateSnapshot(objectType, snapshotObjectFields);
                }
            }
            return(new DataModel(objectType, root, snapshot));
        }