Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="Result"></typeparam>
        /// <typeparam name="T"></typeparam>
        /// <param name="tag"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public virtual IEnumerable <Result> QueryForEnumerable <Result, T>(SqlTag tag, EasySqlParameter <T> parameter)
        {
            var format = tag.Format(parameter);
            var temp   = this.SqlExecuter.QueryForEnumerable <Result>(format.ToString(), CommandType.Text, format.Parameters.ToArray());

            return(temp == null ? new Result[0] : temp);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tag"></param>
        /// <param name="parameter"></param>
        /// <param name="callmode"></param>
        /// <returns></returns>
        public virtual object Call <T>(SqlTag tag, EasySqlParameter <T> parameter, CallMode callmode)
        {
            var format = tag.Format(parameter);

            if ((callmode & CallMode.ExecuteScalar) == CallMode.ExecuteScalar)
            {
                if ((callmode & CallMode.CommandText) == CallMode.CommandText)
                {
                    return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.Text, format.Parameters.ToArray()));
                }

                if ((callmode & CallMode.CommandStoredProcedure) == CallMode.CommandStoredProcedure)
                {
                    return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.StoredProcedure, format.Parameters.ToArray()));
                }

                if ((callmode & CallMode.CommandTableDirect) == CallMode.CommandTableDirect)
                {
                    return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.TableDirect, format.Parameters.ToArray()));
                }

                return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.Text, format.Parameters.ToArray()));
            }

            if ((callmode & CallMode.ExecuteNonQuery) == CallMode.ExecuteNonQuery)
            {
                if ((callmode & CallMode.CommandText) == CallMode.CommandText)
                {
                    return(this.SqlExecuter.ExecuteNonQuery(format.ToString(), CommandType.Text, format.Parameters.ToArray()));
                }

                if ((callmode & CallMode.CommandStoredProcedure) == CallMode.CommandStoredProcedure)
                {
                    return(this.SqlExecuter.ExecuteNonQuery(format.ToString(), CommandType.StoredProcedure, format.Parameters.ToArray()));
                }

                if ((callmode & CallMode.CommandTableDirect) == CallMode.CommandTableDirect)
                {
                    return(this.SqlExecuter.ExecuteNonQuery(format.ToString(), CommandType.TableDirect, format.Parameters.ToArray()));
                }

                return(this.SqlExecuter.ExecuteNonQuery(format.ToString(), CommandType.Text, format.Parameters.ToArray()));
            }

            return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.Text, format.Parameters.ToArray()));
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tag"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public virtual int Update <T>(SqlTag tag, EasySqlParameter <T> parameter)
        {
            var format = tag.Format(parameter);

            return(this.SqlExecuter.Update(format.ToString(), CommandType.Text, format.Parameters.ToArray()));
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="Result"></typeparam>
        /// <typeparam name="T"></typeparam>
        /// <param name="tag"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public virtual Result QueryForObject <Result, T>(SqlTag tag, EasySqlParameter <T> parameter)
        {
            var format = tag.Format(parameter);

            return(this.SqlExecuter.QueryForObject <Result>(format.ToString(), CommandType.Text, format.Parameters.ToArray()));
        }
Esempio n. 5
0
        /// <summary>
        /// 插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tag"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public virtual object Insert <T>(SqlTag tag, EasySqlParameter <T> parameter)
        {
            var format = tag.Format(parameter);

            if (format.ReturnType.IsNullOrEmpty())
            {
                return(this.SqlExecuter.Insert(format.ToString(), CommandType.Text, format.Parameters.ToArray()));
            }

            var @object = this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.Text, format.Parameters.ToArray());

            switch (format.ReturnType)
            {
            case "byte":
                return(Convert.ChangeType(@object, TypeCode.Byte));

            case "sbyte":
                return(Convert.ChangeType(@object, TypeCode.SByte));

            case "bool":
                return(Convert.ChangeType(@object, TypeCode.Boolean));

            case "char":
                return(Convert.ChangeType(@object, TypeCode.Char));

            case "datetime":
                return(Convert.ChangeType(@object, TypeCode.DateTime));

            case "decimal":
                return(Convert.ChangeType(@object, TypeCode.Decimal));

            case "double":
                return(Convert.ChangeType(@object, TypeCode.Double));

            case "float":
                return(Convert.ChangeType(@object, TypeCode.Single));

            case "int":
                return(Convert.ChangeType(@object, TypeCode.Int32));

            case "uint":
                return(Convert.ChangeType(@object, TypeCode.UInt32));

            case "short":
                return(Convert.ChangeType(@object, TypeCode.Int16));

            case "ushort":
                return(Convert.ChangeType(@object, TypeCode.UInt16));

            case "long":
                return(Convert.ChangeType(@object, TypeCode.Int64));

            case "ulong":
                return(Convert.ChangeType(@object, TypeCode.UInt64));

            case "guid":
                return(@object == null ? Guid.Empty : Guid.Parse(@object.ToString()));

            case "string":
                return(Convert.ChangeType(@object, TypeCode.String));
            }

            return(@object);
        }