コード例 #1
0
 /// <summary>
 /// 创建运行时记录的表信息,这在关系数据库中体现为创建表
 /// 该方法一般用于单元测试
 /// </summary>
 /// <typeparam name="T"></typeparam>
 public static void RuntimeBuild()
 {
     DataModel.RuntimeBuild();
 }
コード例 #2
0
 /// <summary>
 /// 在数据层中销毁数据模型
 /// </summary>
 /// <typeparam name="T"></typeparam>
 public static void Dispose()
 {
     DataModel.Drop();
 }
コード例 #3
0
        /// <summary>
        /// 1对多的引用关系的读取
        /// </summary>
        /// <param name="rootId"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private object ReadOneToMore(PropertyRepositoryAttribute tip, ParameterRepositoryAttribute prmTip, DomainObject parent, object rootId, object masterId, QueryLevel level)
        {
            using (var temp = SqlHelper.BorrowDatas())
            {
                var datas = temp.Item;
                QueryRootAndSlaveIds(rootId, masterId, datas);

                Type implementType = null;
                if (parent == null)
                {
                    //说明还在构造阶段,或者是内部调用
                    implementType = prmTip?.ImplementType ?? this.Middle.ObjectType; //middle表对应的是属性的基类类型
                }
                else
                {
                    implementType = this.Middle.ObjectType; //middle表对应的是属性的基类类型
                }
                var list        = CreateList(parent, implementType, tip.Property);
                var elementType = this.Middle.ElementType;

                if (this.Type == DataTableType.AggregateRoot)
                {
                    //引用了多个外部内聚根
                    var model       = DataModel.Create(elementType);
                    var root        = model.Root;
                    var slaveIdName = GeneratedField.SlaveIdName;
                    var slaveTip    = root.ObjectTip;

                    var queryLevel = GetQueryAggreateRootLevel(level);
                    if (slaveTip.Snapshot)  //如果外部内聚根是有快照的,那么当数据不存在时,加载快照
                    {
                        foreach (var data in datas)
                        {
                            var slaveId = data.Get(slaveIdName);
                            var item    = root.QuerySingle(slaveId, queryLevel);
                            if (((IDomainObject)item).IsEmpty())
                            {
                                //加载快照
                                item = model.Snapshot.QuerySingle(slaveId, QueryLevel.None);
                            }
                            list.Add(item);
                        }
                    }
                    else
                    {
                        foreach (var data in datas)
                        {
                            var slaveId = data.Get(slaveIdName);
                            var item    = root.QuerySingle(slaveId, queryLevel);
                            if (!((IDomainObject)item).IsEmpty())
                            {
                                list.Add(item);
                            }
                        }
                    }
                }
                else
                {
                    var slaveIdName = GeneratedField.SlaveIdName;
                    foreach (var data in datas)
                    {
                        var slaveId = data.Get(slaveIdName);
                        var item    = this.QuerySingle(rootId, slaveId);
                        if (!((IDomainObject)item).IsEmpty())
                        {
                            list.Add(item);
                        }
                    }
                }
                return(list);
            }
        }