Esempio n. 1
0
 /// <summary>
 /// Executes the non query.
 /// </summary>
 /// <param name="conn">The conn.</param>
 /// <param name="commandText">The command text.</param>
 /// <param name="cmdParams">The CMD params.</param>
 /// <returns>System.Int32.</returns>
 public static int ExecuteNonQuery(DbConnection conn, string commandText, CmdParams cmdParams)
 {
     using (var cmd = CreateCommand(conn, commandText, cmdParams))
     {
         return(cmd.ExecuteNonQuery());
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Executes the scalar.
 /// </summary>
 /// <param name="conn">The conn.</param>
 /// <param name="commandText">The command text.</param>
 /// <param name="cmdParams">The CMD params.</param>
 /// <returns>System.Object.</returns>
 public static object ExecuteScalar(DbConnection conn, string commandText, CmdParams cmdParams)
 {
     using (var cmd = CreateCommand(conn, commandText, cmdParams))
     {
         return(cmd.ExecuteScalar());
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Creates the command.
        /// </summary>
        /// <param name="conn">The conn.</param>
        /// <param name="commandText">The command text.</param>
        /// <param name="cmdParams">The CMD params.</param>
        /// <returns>DbCommand.</returns>
        public static DbCommand CreateCommand(DbConnection conn, string commandText, CmdParams cmdParams)
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            var result = conn.CreateCommand();

            result.CommandText = commandText;
            result.CommandType = CommandType.Text;
            if (cmdParams != null)
            {
                foreach (var param in cmdParams)
                {
                    object value;
                    if (param.Value is Guid)
                    {
                        value = ((Guid)param.Value).ToGuidStr();
                    }
                    else if (param.Value is bool)
                    {
                        value = ((bool)param.Value).ToShort();
                    }
                    else
                    {
                        value = param.Value;
                    }
                    result.AddParam(param.Key, value);
                }
            }

            return(result);
        }
Esempio n. 4
0
 /// <summary>
 /// Reads the collection.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="conn">The conn.</param>
 /// <param name="commandText">The command text.</param>
 /// <param name="cmdParams">The CMD params.</param>
 /// <param name="excludeFields">The exclude fields.</param>
 /// <returns>IEnumerable{``0}.</returns>
 public static IEnumerable <T> ReadCollection <T>(
     DbConnection conn,
     string commandText,
     CmdParams cmdParams,
     string[] excludeFields)
 {
     return(ReadCollection <T>(conn, commandText, cmdParams, excludeFields, null));
 }
Esempio n. 5
0
 public void Add(string constraint, CmdParams Params)
 {
     _Constraints.Add(constraint);
     if (Params != null)
     {
         foreach (var p in Params)
         {
             this.Params.Add(p.Key, p.Value);
         }
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Executes the reader.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="conn">The conn.</param>
 /// <param name="commandText">The command text.</param>
 /// <param name="cmdParams">The CMD params.</param>
 /// <param name="func">The func.</param>
 /// <returns>``0.</returns>
 public static T ExecuteReader <T>(DbConnection conn, string commandText, CmdParams cmdParams, Func <IDataReader, T> func) where T : class
 {
     using (var cmd = CreateCommand(conn, commandText, cmdParams))
         using (var reader = cmd.ExecuteReader())
         {
             if (reader.Read())
             {
                 return(func(reader));
             }
             else
             {
                 return(null);
             }
         }
 }
Esempio n. 7
0
 /// <summary>
 /// Reads the collection.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="conn">The conn.</param>
 /// <param name="commandText">The command text.</param>
 /// <param name="cmdParams">The CMD params.</param>
 /// <param name="excludeFields">The exclude fields.</param>
 /// <param name="changeTracker">The change tracker.</param>
 /// <returns>IEnumerable{``0}.</returns>
 public static IEnumerable <T> ReadCollection <T>(
     DbConnection conn,
     string commandText,
     CmdParams cmdParams,
     string[] excludeFields,
     ObjectsChangeTracker changeTracker)
 {
     using (var cmd = CreateCommand(conn, commandText, cmdParams))
         using (var reader = cmd.ExecuteReader())
         {
             while (reader.Read())
             {
                 yield return(reader.ToObject <T>(null, excludeFields, changeTracker));
             }
         }
 }
Esempio n. 8
0
 public static T ExecuteScalar<T>(DbConnection conn, string commandText, CmdParams cmdParams)
 {
     object result = ExecuteScalar(conn, commandText, cmdParams);
     if (typeof(T) == typeof(Guid))
     {
         if(result == null)
         {
             return (T)((object)Guid.Empty);
         }
         return (T)((object)new Guid(result.ToString()));
     }
     if (result is DBNull || result == null)
     {
         return default(T);
     }
     return (T)Convert.ChangeType(result, typeof(T));
 }
 public static DbDataReader ExecuteReader(DbConnection conn, CommandType commandType, string commandText, CmdParams cmdParams)
 {
     using (var cmd = CreateCommand(conn, commandType, commandText, cmdParams))
     {
         return(cmd.ExecuteReader(CommandBehavior.CloseConnection));
     }
 }
 public static T ExecuteReaderStruct <T>(DbConnection conn, CommandType commandType, string commandText, CmdParams cmdParams, Func <DbDataReader, T> func) where T : struct
 {
     using (var cmd = CreateCommand(conn, commandType, commandText, cmdParams))
         using (var reader = cmd.ExecuteReader())
         {
             if (reader.Read())
             {
                 return(func(reader));
             }
             else
             {
                 return(default(T));
             }
         }
 }
 public static IEnumerable <T> ExecuteReaderEnum <T>(DbConnection conn, CommandType commandType, string commandText, CmdParams cmdParams, Func <DbDataReader, T> func)
 {
     using (var cmd = CreateCommand(conn, commandType, commandText, cmdParams))
         using (var reader = cmd.ExecuteReader())
         {
             while (reader.Read())
             {
                 yield return(func(reader));
             }
         }
 }
 public static T ExecuteReaderStruct <T>(this DbConnection conn, CommandType commandType, string commandText, CmdParams cmdParams, Func <DbDataReader, T> func) where T : struct
 {
     return(DBTools.ExecuteReaderStruct <T>(conn, commandType, commandText, cmdParams, func));
 }
 public static IEnumerable <T> ExecuteReaderEnum <T>(this DbConnection conn, CommandType commandType, string commandText, CmdParams cmdParams, Func <DbDataReader, T> func)
 {
     return(DBTools.ExecuteReaderEnum <T>(conn, commandType, commandText, cmdParams, func));
 }
 public static DbDataReader ExecuteReader(this DbConnection conn, CommandType commandType, string commandText, CmdParams cmdParams)
 {
     return(DBTools.ExecuteReader(conn, commandType, commandText, cmdParams));
 }
 public static T ExecuteScalar <T>(this DbConnection conn, CommandType commandType, string commandText, CmdParams cmdParams)
 {
     return(DBTools.ExecuteScalar <T>(conn, commandType, commandText, cmdParams));
 }
 public static int ExecuteNonQuery(this DbConnection conn, CommandType commandType, string commandText, CmdParams cmdParams)
 {
     return(DBTools.ExecuteNonQuery(conn, commandType, commandText, cmdParams));
 }
Esempio n. 17
0
 /// <summary>
 /// Executes the reader.
 /// </summary>
 /// <param name="conn">The conn.</param>
 /// <param name="commandText">The command text.</param>
 /// <param name="cmdParams">The CMD params.</param>
 /// <returns>IDataReader.</returns>
 public static IDataReader ExecuteReader(DbConnection conn, string commandText, CmdParams cmdParams)
 {
     using (var cmd = CreateCommand(conn, commandText, cmdParams))
     {
         return(cmd.ExecuteReader());
     }
 }
Esempio n. 18
0
 public FilterConstraints()
 {
     _Constraints = new List <string>();
     Params       = new CmdParams();
 }