Ejemplo n.º 1
0
        public static bool ExecuteNonQuery(string script, CommandType cmdType = CommandType.Text,
                                           params DbParameter[] @params)
        {
            using (var con = GetDbConnection(CONNECTION_NAME))
            {
                var cmd = con.CreateCommand();
                cmd.CommandText = script;
                cmd.CommandType = cmdType;
                cmd.Connection  = con;
                if (@params != null && @params.Count() > 0)
                {
                    foreach (var p in @params)
                    {
                        if (p != null)
                        {
                            cmd.Parameters.Add(p);
                        }
                    }
                }
                con.Open();
#if DEBUG
                DateTime dt1 = DateTime.Now;
#endif
                var result = (cmd.ExecuteNonQuery() > 0);
#if DEBUG
                DateTime dt2 = DateTime.Now;

                DbQueryDetailHelper.QueryDetail += DbQueryDetailHelper.GetQueryDetail(cmd.CommandText, dt1, dt2, cmd.Parameters);
#endif
                con.Close();
                return(result);
            }
        }
Ejemplo n.º 2
0
        public static List <T> ExecuteList <T>(string script, Func <T, string, object, bool> predicate, CommandType cmdType = CommandType.Text,
                                               params DbParameter[] @params) where T : new()
        {
            using (var con = GetDbConnection(CONNECTION_NAME))
            {
                var cmd = con.CreateCommand();
                cmd.CommandText = script;
                cmd.CommandType = cmdType;
                cmd.Connection  = con;
                if (@params != null && @params.Count() > 0)
                {
                    foreach (var p in @params)
                    {
                        if (p != null)
                        {
                            cmd.Parameters.Add(p);
                        }
                    }
                }
                con.Open();
#if DEBUG
                DateTime dt1 = DateTime.Now;
#endif
                var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
#if DEBUG
                DateTime dt2 = DateTime.Now;

                DbQueryDetailHelper.QueryDetail += DbQueryDetailHelper.GetQueryDetail(cmd.CommandText, dt1, dt2, cmd.Parameters);
#endif
                return(ExecuteList <T>(reader, predicate).ToList());
            }
        }
Ejemplo n.º 3
0
        public static List <T> ExecutePagingList <T>(string script,
                                                     Pagination paging, Func <T, string, object, bool> predicate, params DbParameter[] @params) where T : new()
        {
            using (var con = GetDbConnection(CONNECTION_NAME))
            {
                var cmd      = con.CreateCommand();
                var provider = con.GetProvider();

                cmd.CommandText = provider.GeneratePagingCountScript(script);
                cmd.CommandType = CommandType.Text;
                cmd.Connection  = con;

                if (@params != null && @params.Count() > 0)
                {
                    foreach (var p in @params)
                    {
                        if (p != null)
                        {
                            cmd.Parameters.Add(p);
                        }
                    }
                }

                con.Open();
#if DEBUG
                DateTime dt1 = DateTime.Now;
#endif
                paging.RowCount = Convert.ToInt32(cmd.ExecuteScalar().ToString());

#if DEBUG
                DateTime dt2 = DateTime.Now;

                DbQueryDetailHelper.QueryDetail += DbQueryDetailHelper.GetQueryDetail(cmd.CommandText, dt1, dt2, cmd.Parameters);
#endif

                cmd = provider.WrapPagingCommand(script, paging, @params);
#if DEBUG
                dt1 = DateTime.Now;
#endif
                var reader = cmd.ExecuteReader();
#if DEBUG
                dt2 = DateTime.Now;

                DbQueryDetailHelper.QueryDetail += DbQueryDetailHelper.GetQueryDetail(cmd.CommandText, dt1, dt2, cmd.Parameters);
#endif
                var result = ExecuteList <T>(reader, predicate).ToList();
                return(result);
            }
        }