Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tip"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private object ReadSnapshot(PropertyRepositoryAttribute tip, object id)
        {
            var objectTip = ObjectRepositoryAttribute.GetTip(tip.PropertyType, true);

            if (objectTip.Snapshot)  //如果外部内聚根是有快照的,那么当数据不存在时,加载快照
            {
                var idName = _getIdName(tip.PropertyName);
                var root   = DataModel.Create(objectTip.ObjectType).Root;
                return(root.QuerySingle(id, QueryLevel.None));
            }
            return(DomainObject.GetEmpty(tip.PropertyType));
        }
 private void InitObjectType(Type objectType)
 {
     this.ObjectType = objectType;
     if (this.Type == DataTableType.Middle)
     {
         this.ElementType = this.ObjectType.ResolveElementType();
     }
     else
     {
         this.ObjectTip = ObjectRepositoryAttribute.GetTip(this.ObjectType, true);
     }
 }
        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));
        }
 private void InitObjectType(Type objectType, PropertyRepositoryAttribute tip)
 {
     this.ObjectType = objectType;
     if (this.Type == DataTableType.Middle)
     {
         this.ElementType = tip.GetElementType();
     }
     else if (this.Type == DataTableType.AggregateRoot)
     {
         this.ObjectTip = ObjectRepositoryAttribute.GetTip(this.ObjectType, true);
     }
     else
     {
         //对于值对象和引用对象,如果没有定义ObjectRepositoryAttribute,那么使用根的ObjectRepositoryAttribute
         this.ObjectTip = ObjectRepositoryAttribute.GetTip(this.ObjectType, false);
         if (this.ObjectTip == null)
         {
             this.ObjectTip = this.Root.ObjectTip;
         }
     }
 }