Exemple #1
0
        /// <summary>
        /// 贪婪加载某个属性
        /// </summary>
        /// <param name="property">需要贪婪加载的托管属性。可以是一个引用属性,也可以是一个组合子属性。</param>
        private void EagerLoad(ConcreteProperty property)
        {
            if (this.EagerLoadOptions == null)
            {
                this.EagerLoadOptions = new EagerLoadOptions();
            }

            this.EagerLoadOptions.CoreList.Add(property);
        }
Exemple #2
0
        private static ConcreteProperty ConvertParameter(object pathParameter, bool checkOwnerType = true)
        {
            if (pathParameter == null)
            {
                throw new ArgumentNullException("pathParameter");
            }

            ConcreteProperty res = null;

            var property = pathParameter as IProperty;

            if (property != null)
            {
                var refProperty = property as IRefProperty;
                if (refProperty != null)
                {
                    res = new ConcreteProperty(refProperty.RefIdProperty);
                }
                else
                {
                    res = new ConcreteProperty(property);
                }
            }
            else
            {
                res = pathParameter as ConcreteProperty;
                if (res == null)
                {
                    throw new InvalidProgramException(string.Format(
                                                          "参数 {0} 的类型 {1} 不符合规定。原因:RedundantPath 构造函数中的参数必须是 Rafy.Domain.IProperty 类型或者 Rafy.ManagedProperty.ConcreteProperty 类型。",
                                                          pathParameter, pathParameter.GetType()
                                                          ));
                }
                else
                {
                    //如果给定的 ConcreteProperty 中使用的引用实体属性,那么需要转换为引用 Id 属性。
                    var refProperty = res.Property as IRefProperty;
                    if (refProperty is IRefEntityProperty)
                    {
                        res = new ConcreteProperty(refProperty.RefIdProperty, res.Owner);
                    }
                }
            }

            if (checkOwnerType && res.Owner.IsAbstract)
            {
                throw new InvalidProgramException(string.Format(
                                                      "冗余属性路径中的引用属性 {0}.{1} 定义在抽象的父类中,不能被直接使用。请使用 Rafy.ManagedProperty.ConcreteProperty 类型为该引用属性指定具体的子类型。",
                                                      res.Owner.Name, res.Property.Name
                                                      ));
            }

            return(res);
        }
        public CommonSection()
        {
            OuterLine  = null;
            Rebars     = new List <Circle2D>();
            PreRebars  = new List <Circle2D>();
            InnerLines = new List <Polygon2D>();
            Xstrip     = new List <double[]>();
            Ystrip     = new List <double[]>();
            xs         = new List <double>();
            ys         = new List <double>();
            Axs        = new List <double>();
            Ays        = new List <double>();

            Conc              = new ConcreteProperty();
            MRebar            = new Reinforcement("HRB400", 400, 1, 1, 0, 0);
            SRebar            = new Reinforcement("HRB400", 400, 1, 1, 0, 0);
            PrestressProperty = new Prestress("G270", 1860);
        }
        public UTCSViewModel()
        {
            _selConcreteList = new Dictionary <int, string>();
            _selRebarList    = new Dictionary <int, string>();
            _selPreRebarList = new Dictionary <int, string>();


            _selConcreteList.Add(0, "AASHTO-Fc45");
            _selConcreteList.Add(1, "AASHTO-Fc35");
            _selConcreteList.Add(2, "JTG-C40");
            _selConcreteList.Add(3, "JTG-C50");

            _concID   = 0;
            _concrete = new ConcreteProperty(_selConcreteList[_concID]);

            _selRebarList.Add(0, "HRB400");
            _selRebarList.Add(1, "HRB500");
            _rebarID = 0;
            _rebar   = new Reinforcement(_selRebarList[_rebarID]);


            _selPreRebarList.Add(0, "Grade270-12.7");
            _selPreRebarList.Add(1, "Grade270-15.2");
            _prerebarID = 0;
            _prerebar   = new Prestress(_selPreRebarList[_prerebarID], 1860);


            commonSection                   = new CommonSection();
            commonSection.Conc              = _concrete;
            commonSection.MRebar            = _rebar;
            commonSection.SRebar            = _rebar;
            commonSection.PrestressProperty = _prerebar;

            _rebarCollection   = GetRebarCollection(ref commonSection);
            _sectionCollection = GetSectionCollection(ref commonSection);

            _isVertMoment  = true;
            _isCompression = true;

            _message = "Hello Kitty";
        }
Exemple #5
0
        protected override void UpdateRedundancy(Entity entity, ConcreteProperty redundancy, object newValue, IList <ConcreteProperty> refPathes, object lastRefId)
        {
            /*********************** 代码块解释 *********************************
             *
             * 假定场景是:
             * refPathes: D(CRef,AName) -> C(BRef) -> B(ARef),
             * lastRefId: AId。(B.ARef 是最后一个引用属性)
             * 则对应生成的 SQL 是:
             * update D set AName = @AName where CId in (
             *     select id from C where BId in (
             *          select id from B where AId = @AId
             *     )
             * )
             * 如果 B、C 表也有冗余属性,对应的 SQL 则是:
             * update B Set AName = @AName where AId = @BId
             * update C set AName = @AName where BId in (
             *     select id from B where AId = @AId
             * )
             *
             **********************************************************************/

            //准备所有用到的 DbTable
            var table     = RdbTableFinder.TableFor(redundancy.Owner);
            var refTables = new RefPropertyTable[refPathes.Count];

            for (int i = 0, c = refPathes.Count; i < c; i++)
            {
                var refProperty = refPathes[i];
                var refTable    = RdbTableFinder.TableFor(refProperty.Owner);
                if (refTable == null)
                {
                    ORMHelper.ThrowBasePropertyNotMappedException(refProperty.Name, refProperty.Owner);
                }

                refTables[i] = new RefPropertyTable
                {
                    RefProperty = refProperty,
                    OwnerTable  = refTable
                };
            }

            var sql = new ConditionalSql();

            //SQL: UPDATE D SET AName = {0} WHERE
            sql.Append("UPDATE ").AppendQuoteName(table)
            .Append(" SET ").AppendQuote(table, table.Translate(redundancy.Property))
            .Append(" = ").AppendParameter(newValue).Append(" WHERE ");

            int quoteNeeded = 0;

            if (refTables.Length > 1)
            {
                //中间的都生成 Where XX in
                var inWherePathes = refTables.Take(refTables.Length - 1).ToArray();
                for (int i = 0; i < inWherePathes.Length; i++)
                {
                    var inRef = inWherePathes[i];

                    //SQL: CId In (
                    sql.AppendQuote(table, inRef.OwnerTable.Translate(inRef.RefProperty.Property))
                    .Append(" IN (").AppendLine();
                    quoteNeeded++;

                    var nextRef = refTables[i + 1];

                    //SQL: SELECT Id FROM C WHERE
                    var nextRefOwnerTable = nextRef.OwnerTable;
                    sql.Append(" SELECT ").AppendQuote(nextRefOwnerTable, nextRefOwnerTable.PKColumn.Name)
                    .Append(" FROM ").AppendQuoteName(nextRefOwnerTable)
                    .Append(" WHERE ");
                }
            }

            //最后一个,生成SQL: BId = {1}
            var lastRef = refTables[refTables.Length - 1];

            sql.AppendQuote(table, lastRef.OwnerTable.Translate(lastRef.RefProperty.Property))
            .Append(" = ").AppendParameter(lastRefId);

            while (quoteNeeded > 0)
            {
                sql.AppendLine(")");
                quoteNeeded--;
            }

            //执行最终的 SQL 语句
            using (var dba = _dataProvider.CreateDbAccesser())
            {
                dba.ExecuteText(sql, sql.Parameters);
            }
        }
Exemple #6
0
        public override void RefreshRedundancy(ConcreteProperty redundancy)
        {
            /*********************** 代码块解释 *********************************
             * http://blog.csdn.net/peng790/article/details/6585202
             *
             * 假定场景是:
             * D(CRef,AName) -> C(BRef) -> B(ARef) -> A(Name);
             * 则对应生成的 SQL 是:
             * update D set AName = @AName where CId in (
             *     select id from C where BId in (
             *          select id from B where AId = @AId
             *     )
             * )
             * 如果 B、C 表也有冗余属性,对应的 SQL 则是:
             * update B Set AName = @AName where AId = @AId
             * update C set AName = @AName where BId in (
             *     select id from B where AId = @AId
             * )
             *
             **********************************************************************/

            //update B set AName = A.Name FROM A WHERE A.ID = b.AId
            //update C set AName = A.Name FROM A INNER JOIN B ON A.Id = B.AId WHERE B.Id = C.BId
            //update D set AName = A.Name FROM A INNER JOIN B ON A.Id = B.AId INNER JOIN C ON B.Id = c.BId WHERE C.Id = D.CId

            ////准备所有用到的 DbTable
            //var table = RdbTableFinder.TableFor(path.Redundancy.Owner);
            //var refTables = new RefPropertyTable[refPathes.Count];
            //for (int i = 0, c = refPathes.Count; i < c; i++)
            //{
            //    var refProperty = refPathes[i];
            //    var refTable = RdbTableFinder.TableFor(refProperty.Owner);
            //    if (refTable == null)
            //    {
            //        ORMHelper.ThrowBasePropertyNotMappedException(refProperty.Name, refProperty.Owner);
            //    }

            //    refTables[i] = new RefPropertyTable
            //    {
            //        RefProperty = refProperty,
            //        OwnerTable = refTable
            //    };
            //}

            //var sql = new ConditionalSql();
            ////SQL: UPDATE D SET AName = {0} WHERE
            //sql.Append("UPDATE ").AppendQuoteName(table)
            //    .Append(" SET ").AppendQuote(table, table.Translate(redundancy.Property))
            //    .Append(" = ").AppendParameter(newValue).Append(" WHERE ");

            //int quoteNeeded = 0;
            //if (refTables.Length > 1)
            //{
            //    //中间的都生成 Where XX in
            //    var inWherePathes = refTables.Take(refTables.Length - 1).ToArray();
            //    for (int i = 0; i < inWherePathes.Length; i++)
            //    {
            //        var inRef = inWherePathes[i];

            //        //SQL: CId In (
            //        sql.AppendQuote(table, inRef.OwnerTable.Translate(inRef.RefProperty.Property))
            //            .Append(" IN (").AppendLine();
            //        quoteNeeded++;

            //        var nextRef = refTables[i + 1];

            //        //SQL: SELECT Id FROM C WHERE
            //        var nextRefOwnerTable = nextRef.OwnerTable;
            //        sql.Append(" SELECT ").AppendQuote(nextRefOwnerTable, nextRefOwnerTable.PKColumn.Name)
            //            .Append(" FROM ").AppendQuoteName(nextRefOwnerTable)
            //            .Append(" WHERE ");
            //    }
            //}

            ////最后一个,生成SQL: BId = {1}
            //var lastRef = refTables[refTables.Length - 1];
            //sql.AppendQuote(table, lastRef.OwnerTable.Translate(lastRef.RefProperty.Property))
            //    .Append(" = ").AppendParameter(lastRefId);

            //while (quoteNeeded > 0)
            //{
            //    sql.AppendLine(")");
            //    quoteNeeded--;
            //}

            ////执行最终的 SQL 语句
            //using (var dba = _dataProvider.CreateDbAccesser())
            //{
            //    dba.ExecuteText(sql, sql.Parameters);
            //}
        }
 /// <summary>
 /// 完整刷新指定的冗余属性。
 /// </summary>
 /// <param name="redundancy">The redundancy.</param>
 public abstract void RefreshRedundancy(ConcreteProperty redundancy);
 /// <summary>
 /// 更新某个冗余属性
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="redundancy">更新指定的冗余属性</param>
 /// <param name="newValue">冗余属性的新值</param>
 /// <param name="refPathes">从冗余属性声明类型开始的一个引用属性集合,
 /// 将会为这个集合路径生成更新的 Where 条件。</param>
 /// <param name="lastRefId">引用路径中最后一个引用属性对应的值。这个值将会作为 Where 条件的值。</param>
 protected abstract void UpdateRedundancy(Entity entity, ConcreteProperty redundancy, object newValue, IList <ConcreteProperty> refPathes, object lastRefId);