Example #1
0
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="objectType"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private DomainObject CreateObject(Type objectType, DynamicData data)
        {
            DomainObject obj = null;

            if (this.IsDynamic)
            {
                if (data.IsEmpty())
                {
                    obj = (DomainObject)DomainObject.GetEmpty(this.ObjectType);
                }
                else
                {
                    obj = CreateObjectImpl(this.DynamicType, this.DynamicType.ObjectType, data);
                    (obj as IDynamicObject).Define = this.DynamicType.Define;
                }
            }
            else
            {
                if (data.IsEmpty())
                {
                    obj = (DomainObject)DomainObject.GetEmpty(objectType);
                }
                else
                {
                    obj = CreateObjectImpl(objectType, objectType, data);
                }
            }
            return(obj);
        }
Example #2
0
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="objectType"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private DomainObject CreateObject(Type objectType, DynamicData data, QueryLevel level)
        {
            DomainObject obj = null;

            if (this.IsDynamic)
            {
                if (data.IsEmpty())
                {
                    obj = (DomainObject)DomainObject.GetEmpty(this.ObjectType);
                }
                else
                {
                    obj = CreateObjectImpl(this.DynamicType, this.DynamicType.ObjectType, data, level);
                }
            }
            else
            {
                if (data.IsEmpty())
                {
                    obj = (DomainObject)DomainObject.GetEmpty(objectType);
                }
                else
                {
                    obj = CreateObjectImpl(objectType, objectType, data, level);
                }
            }
            return(obj);
        }
Example #3
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));
        }
Example #4
0
        internal object QuerySingle(string expression, Action <DynamicData> fillArg, QueryLevel level)
        {
            expression = GetEntryExpression(expression);
            var exp = QueryObject.Create(this, expression, level);

            object result = null;

            UseDataEntry(exp, fillArg, (entry) =>
            {
                result = GetObjectFromEntry(entry, level);
            });
            return(result != null ? result : DomainObject.GetEmpty(this.ObjectType));
        }
Example #5
0
        private object ReadMemberFromData(PropertyRepositoryAttribute tip, DynamicData data)
        {
            var name = _getNameWithSeparated(tip.PropertyName);

            using (var temp = SqlHelper.BorrowData())
            {
                var subData = temp.Item;
                foreach (var p in data)
                {
                    var dataName = p.Key;
                    if (dataName.StartsWith(name))
                    {
                        var subName = _getNextName(dataName);
                        subData.Add(subName, p.Value);
                    }
                }

                if (subData.IsEmpty())
                {
                    if (tip.DomainPropertyType == DomainPropertyType.AggregateRoot)
                    {
                        var idName = _getIdName(tip.PropertyName);
                        var id     = data.Get(idName);
                        return(ReadSnapshot(tip, id));
                    }
                    return(DomainObject.GetEmpty(tip.PropertyType));
                }


                var  typeKey    = (string)subData.Get(GeneratedField.TypeKeyName);
                Type objectType = null;
                if (this.IsDynamic)
                {
                    objectType = tip.PropertyType;
                }
                else
                {
                    objectType = string.IsNullOrEmpty(typeKey) ? tip.PropertyType : DerivedClassAttribute.GetDerivedType(typeKey);
                }


                var child = GetRuntimeTable(this, tip.PropertyName, objectType);
                //先尝试中构造上下文中得到
                return(child.GetObjectFromConstruct(subData) ?? child.CreateObject(objectType, subData, QueryLevel.None)); //成员始终是QueryLevel.None的方式加载
            }
        }