/// <summary>
        /// Initializes a new instance of the <see cref="BatchInsertSqlSection"/> class.
        /// </summary>
        /// <param name="db">The database.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="entitys">The entitys.</param>
        /// <remarks>
        ///     <para>创建:Teddy</para>
        ///     <para>日期:2018/3/22</para>
        /// </remarks>
        public BatchInsertSqlSection(DataContext db, TableSchema schema, EntityBase[] entitys)
        {
            Check.Require(db != null, "db could not be null.");
            Check.Require(entity != null, "entity could not be null.");

            this.db = db;

            var cols = schema.GetColumns().Where(p => !p.IsAutoIncrement).ToList();

            tableName   = schema.GetTableName();
            columnNames = cols.Select(p => "[" + p.ShortName + "]").ToArray();
            var entityPropertyNames = cols.Select(p => p.EntityPropertyName).ToArray();

            columnTypes  = cols.Select(p => p.DbType).ToArray();
            columnValues = new object[entitys.Length][];
            for (int i = 0; i < entitys.Length; i++)
            {
                var row = new object[cols.Count];
                for (int j = 0; j < cols.Count; j++)
                {
                    var value = entitys[i].GetValue(entityPropertyNames[j]);
                    row[j] = value.Value;
                }
                columnValues[i] = row;
            }


            this.tableName = schema.GetTableName();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DeleteSqlSection"/> class.
        /// </summary>
        /// <param name="db">The 数据库.</param>
        /// <param name="table">The table.</param>
        /// <remarks>
        ///     <para>创建:Teddy</para>
        ///     <para>日期:2016-10-17</para>
        /// </remarks>
        public DeleteSqlSection(DataContext db, TableSchema table)
        {
            Check.Require(db != null, "db could not be null.");
            Check.Require(table != null, "table could not be null.");

            this.db        = db;
            this.table     = table;
            this.tableName = table.GetTableName();
        }
Beispiel #3
0
        /// <summary>
        /// Join是否已经存在
        /// </summary>
        /// <param name="forgeinTable">关联表</param>
        /// <param name="joinType">Join类型</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        /// <remarks>
        ///     <para>创建:Teddy</para>
        ///     <para>日期:2016-10-17</para>
        /// </remarks>
        internal bool ExitJoin(TableSchema forgeinTable, JoinType joinType = JoinType.INNER)
        {
            var tableName  = forgeinTable.GetTableName();
            var joinStruct = new TableStruct {
                TableOrViewAliasName = forgeinTable.TableAliasName, TableOrViewName = tableName, JoinType = joinType
            };

            return(joins.ContainsKey(joinStruct));
        }
Beispiel #4
0
        /// <summary>
        ///添加外键表
        /// </summary>
        /// <param name="foreignTable">外键表</param>
        /// <param name="entityPropertyName">关联的属性名称</param>
        /// <exception cref="System.Exception">已包含重复外键表</exception>
        /// <remarks>
        ///     <para>创建:jason</para>
        ///     <para>日期:2016-11-10</para>
        /// </remarks>
        protected void AddForeignTable(TableSchema foreignTable, string entityPropertyName)
        {
            var tableName = foreignTable.GetTableName();

            if (!foreignTables.ContainsKey(entityPropertyName))
            {
                foreignTables.Add(tableName, new KeyValuePair <string, TableSchema>(entityPropertyName, foreignTable));
            }
            else
            {
                throw new Exception("已包含重复外键表");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Joins the specified forgein table.
        /// </summary>
        /// <param name="forgeinTable">The forgein table.</param>
        /// <param name="onWhere">The on where.</param>
        /// <param name="joinType">Type of the join.</param>
        /// <returns>FromClip.</returns>
        /// <exception cref="NameDuplicatedException">In joins list: tableName -  + tableName</exception>
        /// <remarks><para>创建:Teddy</para>
        /// <para>日期:2016-9-7</para></remarks>
        public FromClip Join(TableSchema forgeinTable, WhereClip onWhere, JoinType joinType = JoinType.INNER)
        {
            var tableName  = forgeinTable.GetTableName();
            var joinStruct = new TableStruct {
                TableOrViewAliasName = forgeinTable.TableAliasName, TableOrViewName = tableName, JoinType = joinType
            };

            if (joins.ContainsKey(joinStruct))
            {
                throw new NameDuplicatedException("In joins list: tableName - " + tableName);
            }

            joins.Add(joinStruct, new KeyValuePair <string, WhereClip>(tableName, onWhere));
            return(this);
        }
        public SelectSqlSection(DataContext db, TableSchema table, WhereClip whereClip, params ExpressionClip[] columns)
        {
            Check.Require(db != null, "db could not be null.");
            Check.Require(table != null, "table could not be null.");

            this.db        = db;
            this.table     = table;
            this.tableName = table.GetTableName();

            this.whereClip = whereClip;

            if (columns != null && columns.Length > 0)
            {
                this.columnNames = new string[columns.Length];
                for (int i = 0; i < columns.Length; ++i)
                {
                    this.columnNames[i] = columns[i].ToString();
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// <remarks>
        ///     <para>创建:Teddy</para>
        ///     <para>日期:2016-10-17</para>
        /// </remarks>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            var tableOrViewName = table.GetTableName();

            if (!tableOrViewName.Contains("["))
            {
                sb.Append('[');
                sb.Append(tableOrViewName);
                sb.Append(']');
            }
            else
            {
                sb.Append(tableOrViewName);
            }

            foreach (TableStruct joinStruct in joins.Keys)
            {
                if (sb.ToString().Contains("JOIN"))
                {
                    sb = new StringBuilder('(' + sb.ToString() + ')');
                }

                KeyValuePair <string, WhereClip> keyWhere = joins[joinStruct];

                sb.Append(GetJoinString(joinStruct.JoinType));

                if (joinStruct.TableOrViewName != keyWhere.Key)
                {
                    if (!joinStruct.TableOrViewName.Contains("["))
                    {
                        sb.Append('[');
                        sb.Append(joinStruct.TableOrViewName);
                        sb.Append(']');
                    }
                    else
                    {
                        sb.Append(joinStruct.TableOrViewName);
                    }
                }

                sb.Append(' ');
                if (!keyWhere.Key.Contains("["))
                {
                    sb.Append('[');
                    sb.Append(keyWhere.Key);
                    sb.Append(']');
                }
                else
                {
                    sb.Append(keyWhere.Key);
                }

                if (joinStruct.TableOrViewName != joinStruct.TableOrViewAliasName)
                {
                    sb.AppendFormat("AS {0} ", joinStruct.TableOrViewAliasName);
                }

                sb.Append(" ON ");
                sb.Append(keyWhere.Value.ToString());
            }

            return(sb.ToString());
        }