コード例 #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);
        }