Пример #1
0
        public virtual T GetSingle(string sql, object where)
        {
            using (IDbConnection conn = DBConnectionFactory.GetConnection(DbType))
            {
                var result = conn.QuerySingleOrDefault <T>(sql, where);

                return(result);
            }
        }
Пример #2
0
        public virtual List <T> Select(string sql, object where)
        {
            using (IDbConnection conn = DBConnectionFactory.GetConnection(DbType))
            {
                var result = conn.Query <T>(sql, where).ToList();

                return(result);
            }
        }
Пример #3
0
        public virtual List <T> Select(object where, Dictionary <string, CompareEnum> compares)
        {
            string sql = SqlBuilder.GetSelectSql <T>(where, compares);

            using (IDbConnection conn = DBConnectionFactory.GetConnection(DbType))
            {
                var result = conn.Query <T>(sql, where).ToList();
                return(result);
            }
        }
Пример #4
0
        public List <T> Query(string sql, IDbTransaction tran)
        {
            var conn = tran == null?DBConnectionFactory.GetConnection(DbType) : tran.Connection;

            var result = tran == null?conn.Query <T>(sql) : conn.Query <T>(sql, null, tran);

            if (tran == null)
            {
                conn.Close();
            }
            return(result.ToList());
        }
Пример #5
0
        public T ExecuteScalar(string sql, IDbTransaction tran)
        {
            var conn = tran == null?DBConnectionFactory.GetConnection(DbType) : tran.Connection;

            var result = tran == null?conn.ExecuteScalar <T>(sql) : conn.ExecuteScalar <T>(sql, null, tran);

            if (tran == null)
            {
                conn.Close();
            }
            return(result);
        }
Пример #6
0
        public virtual bool Update(T entity, object where, IDbTransaction tran = null)
        {
            string        sql  = SqlBuilder.GetUpdateSql(entity, where);
            IDbConnection conn = tran == null?DBConnectionFactory.GetConnection(DbType) : tran.Connection;

            var result = tran == null?conn.Execute(sql, entity) : conn.Execute(sql, entity, tran);

            if (tran == null)
            {
                conn.Close();
            }
            return(result == 1);
        }
Пример #7
0
        public int Execute(string sql, object param, IDbTransaction tran)
        {
            var conn = tran == null?DBConnectionFactory.GetConnection(DbType) : tran.Connection;

            var result = tran == null?conn.Execute(sql, param) : conn.Execute(sql, param, tran);

            if (tran == null)
            {
                conn.Close();
            }

            return(result);
        }
Пример #8
0
        public virtual bool Delete <T>(object where, IDbTransaction tran = null)
        {
            string sql = SqlBuilder.GetDeleteSql <T>(where);

            IDbConnection conn = tran == null?DBConnectionFactory.GetConnection(DbType) : tran.Connection;

            var result = tran == null?conn.Execute(sql, where) : conn.Execute(sql, where, tran);

            if (tran == null)
            {
                conn.Close();
            }
            return(result > 0);
        }
Пример #9
0
        public virtual bool InsertBulk(List <T> entities, IDbTransaction tran = null)
        {
            string sql  = SqlBuilder.GetInsertBulkSql <T>();
            var    conn = tran == null?DBConnectionFactory.GetConnection(DbType) : tran.Connection;

            var result = tran == null?conn.Execute(sql, entities) : conn.Execute(sql, entities, tran);

            if (tran == null)
            {
                conn.Close();
            }

            return(result == entities.Count);
        }