/// <summary>
        /// 获取表达式所指的列特性
        /// </summary>
        /// <param name="sourceCommand">来源Sql语句</param>
        /// <param name="expr">表达式</param>
        /// <returns>表达式所指的列特性</returns>
        internal static DatabaseColumnAttribute GetColumnAttribute(AbstractSqlCommand sourceCommand, MemberExpression expr)
        {
            DatabaseColumnAttribute attr = (sourceCommand != null && sourceCommand.SourceDatabaseTable != null ? sourceCommand.SourceDatabaseTable[expr.Member.Name] : null);

            if (attr == null)
            {
                attr = EntityHelper.InternalGetColumnAttribute(expr.Member.DeclaringType, expr.Member.Name);
            }

            return attr;
        }
        /// <summary>
        /// 获取一定包含数据类型的表达式所指的列特性
        /// </summary>
        /// <param name="sourceCommand">来源Sql语句</param>
        /// <param name="expr">表达式</param>
        /// <returns>表达式所指的列特性</returns>
        internal static DatabaseColumnAttribute GetColumnAttributeWithDbType(AbstractSqlCommand sourceCommand, MemberExpression expr)
        {
            DatabaseColumnAttribute attr = ExpressionHelper.GetColumnAttribute(sourceCommand, expr);

            if (attr != null && !attr.DbType.HasValue)
            {
                attr.DbType = DbTypeHelper.InternalGetDbType(expr.Type);
            }

            return attr;
        }
Esempio n. 3
0
        /// <summary>
        /// 初始化新的Sql语句抽象类
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="rootSource">创建时的根来源</param>
        /// <param name="tableName">表格名称</param>
        /// <exception cref="ArgumentNullException">数据库不能为空</exception>
        protected AbstractSqlCommand(AbstractDatabase database, AbstractSqlCommand rootSource, String tableName)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            this._database       = database;
            this._rootSource     = rootSource;
            this._tableName      = tableName;
            this._parameters     = new List <DataParameter>();
            this._parameterIndex = 0;
        }
Esempio n. 4
0
        /// <summary>
        /// 判断两个Sql语句是否相同
        /// </summary>
        /// <param name="obj">待比较的Sql语句</param>
        /// <returns>两个Sql语句是否相同</returns>
        public override Boolean Equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            AbstractSqlCommand cmd = obj as AbstractSqlCommand;

            if (cmd == null)
            {
                return(false);
            }

            if (this.CommandType != cmd.CommandType)
            {
                return(false);
            }

            if (!String.Equals(this.GetCommandText(), cmd.GetCommandText()))
            {
                return(false);
            }

            if (this._parameters.Count != cmd._parameters.Count)
            {
                return(false);
            }

            for (Int32 i = 0; i < this._parameters.Count; i++)
            {
                if ((this._parameters[i] != null && cmd._parameters[i] == null) || (this._parameters[i] == null && cmd._parameters[i] != null))
                {
                    return(false);
                }

                if (!this._parameters[i].Equals(cmd._parameters[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 5
0
 /// <summary>
 /// 初始化新的有Where语句的Sql语句抽象类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="rootSource">创建时的根来源</param>
 /// <param name="tableName">表格名称</param>
 protected AbstractSqlCommandWithWhere(AbstractDatabase database, AbstractSqlCommand rootSource, String tableName)
     : base(database, rootSource, tableName)
 {
     this._conditionBuilder = new SqlConditionBuilder(this);
 }
        /// <summary>
        /// 获取表达式所指的列名
        /// </summary>
        /// <param name="sourceCommand">来源Sql语句</param>
        /// <param name="expr">表达式</param>
        /// <returns>表达式所指的列名</returns>
        internal static String GetColumnName(AbstractSqlCommand sourceCommand, MemberExpression expr)
        {
            DatabaseColumnAttribute attr = ExpressionHelper.GetColumnAttribute(sourceCommand, expr);

            return (attr != null ? attr.ColumnName : String.Empty);
        }
Esempio n. 7
0
 /// <summary>
 /// 初始化Sql更新语句类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="rootSource">创建时的根来源</param>
 /// <param name="tableName">数据表名称</param>
 internal UpdateCommand(AbstractDatabase database, AbstractSqlCommand rootSource, String tableName)
     : base(database, rootSource, tableName)
 {
     this._updateFields = new List <DataParameter>();
 }
 /// <summary>
 /// 初始化新的有Where语句的Sql语句抽象类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="rootSource">创建时的根来源</param>
 /// <param name="tableName">表格名称</param>
 protected AbstractSqlCommandWithWhere(AbstractDatabase database, AbstractSqlCommand rootSource, String tableName)
     : base(database, rootSource, tableName)
 {
     this._conditionBuilder = new SqlConditionBuilder(this);
 }
Esempio n. 9
0
 /// <summary>
 /// 初始化Sql删除语句类
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="rootSource">创建时的根来源</param>
 /// <param name="tableName">数据表名称</param>
 internal DeleteCommand(AbstractDatabase database, AbstractSqlCommand rootSource, String tableName)
     : base(database, rootSource, tableName)
 {
 }
Esempio n. 10
0
        /// <summary>
        /// 获取指定实体类的Sql语句参数集合
        /// </summary>
        /// <param name="cmd">Sql语句</param>
        /// <param name="entity">实体类</param>
        /// <returns>Sql语句参数集合</returns>
        internal static SqlParameter[] InternalGetSqlParameters(AbstractSqlCommand cmd, Object entity)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();

            if (entity == null)
            {
                return parameters.ToArray();
            }

            Type entityType = entity.GetType();
            PropertyInfo[] props = entityType.GetProperties();

            foreach (PropertyInfo prop in props)
            {
                DatabaseColumnAttribute attr = null;
                DbType? dbType = null;
                Object[] objs = prop.GetCustomAttributes(TypeOfDatabaseColumnAttribute, true);

                foreach (Object obj in objs)
                {
                    if ((attr = obj as DatabaseColumnAttribute) != null)
                    {
                        break;
                    }
                }

                if (attr != null)
                {
                    dbType = attr.DbType;

                    if (!dbType.HasValue)
                    {
                        dbType = DbTypeHelper.InternalGetDbType(prop.PropertyType);
                    }

                    SqlParameter parameter = cmd.CreateSqlParameter(attr.ColumnName, dbType.Value, prop.GetValue(entity, null));
                    parameters.Add(parameter);
                }
            }

            return parameters.ToArray();
        }
Esempio n. 11
0
        /// <summary>
        /// 初始化新的Sql语句抽象类
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="rootSource">创建时的根来源</param>
        /// <param name="tableName">表格名称</param>
        /// <exception cref="ArgumentNullException">数据库不能为空</exception>
        protected AbstractSqlCommand(AbstractDatabase database, AbstractSqlCommand rootSource, String tableName)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            this._database = database;
            this._rootSource = rootSource;
            this._tableName = tableName;
            this._parameters = new List<DataParameter>();
            this._parameterIndex = 0;
        }