Ejemplo n.º 1
0
        /// <summary>
        /// only oracle use
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="conn"></param>
        /// <param name="model"></param>
        /// <param name="sequence"></param>
        /// <param name="tran"></param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public static decimal InsertReturnIdForOracle <T>(this IDbConnection conn, T model, string sequence, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            conn.Execute(builder.GetInsertReturnIdSql <T>(sequence), model, tran, commandTimeout);
            return(GetSequenceCurrent <decimal>(conn, sequence, tran, null));
        }
Ejemplo n.º 2
0
 public async static Task <decimal> InsertReturnIdForOracleAsync <T>(this IDbConnection conn, T model, string sequence, IDbTransaction tran = null, int?commandTimeout = null)
 {
     return(await Task.Run(() =>
     {
         var builder = BuilderFactory.GetBuilder(conn);
         conn.Execute(builder.GetInsertReturnIdSql <T>(sequence), model, tran, commandTimeout);
         return GetSequenceCurrent <decimal>(conn, sequence, tran, null);
     }));
 }
Ejemplo n.º 3
0
        public static async Task <int> DeleteByIdsAsync <T>(this IDbConnection conn, object ids, IDbTransaction tran = null, int?commandTimeout = null)
        {
            if (CommonUtil.ObjectIsEmpty(ids))
            {
                return(0);
            }
            var builder            = BuilderFactory.GetBuilder(conn);
            DynamicParameters dpar = new DynamicParameters();

            dpar.Add("@ids", ids);
            return(await conn.ExecuteAsync(builder.GetDeleteByIdsSql <T>(), dpar, tran, commandTimeout));
        }
Ejemplo n.º 4
0
        public static IEnumerable <dynamic> GetByIdsDynamic <T>(this IDbConnection conn, object ids, string returnFields = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            if (CommonUtil.ObjectIsEmpty(ids))
            {
                return(Enumerable.Empty <dynamic>());
            }
            var builder            = BuilderFactory.GetBuilder(conn);
            DynamicParameters dpar = new DynamicParameters();

            dpar.Add("@ids", ids);
            return(conn.Query(builder.GetByIdsSql <T>(returnFields), dpar, tran, true, commandTimeout));
        }
Ejemplo n.º 5
0
        public static async Task <IEnumerable <dynamic> > GetByIdsWithFieldDynamicAsync <T>(this IDbConnection conn, object ids, string field, string returnFields = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            if (CommonUtil.ObjectIsEmpty(ids))
            {
                return(Enumerable.Empty <dynamic>());
            }
            var builder            = BuilderFactory.GetBuilder(conn);
            DynamicParameters dpar = new DynamicParameters();

            dpar.Add("@ids", ids);
            return(await conn.QueryAsync(builder.GetByIdsWithFieldSql <T>(field, returnFields), dpar, tran, commandTimeout));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// only oracle use
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="conn"></param>
        /// <param name="model"></param>
        /// <param name="sequence"></param>
        /// <param name="tran"></param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public static decimal InsertReturnIdForOracle <T>(this IDbConnection conn, T model, string sequence = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var            builder = BuilderFactory.GetBuilder(conn);
            TableAttribute table   = model.GetType().GetCustomAttributes(false).FirstOrDefault(f => f is TableAttribute) as TableAttribute;

            if (string.IsNullOrEmpty(sequence))
            {
                sequence = table.SequenceName;
            }
            conn.Execute(builder.GetInsertReturnIdSql <T>(sequence), model, tran, commandTimeout);
            decimal id = GetSequenceCurrent <decimal>(conn, sequence, tran, null);

            model.GetType().GetProperty(table.KeyName).SetValue(model, id);
            return(id);
        }
Ejemplo n.º 7
0
        public static PageEntity <dynamic> GetPageForOracleDynamic <T>(this IDbConnection conn, int pageIndex, int pageSize, string where = null, object param = null, string returnFields = null, string orderBy = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);
            PageEntity <dynamic> pageEntity = new PageEntity <dynamic>();

            pageEntity.Total = GetTotal <T>(conn, where, param, tran, commandTimeout);
            if (pageEntity.Total > 0)
            {
                pageEntity.Data = GetByPageIndexDynamic <T>(conn, pageIndex, pageSize, where, param, returnFields, orderBy, tran, commandTimeout);
            }
            else
            {
                pageEntity.Data = Enumerable.Empty <dynamic>();
            }
            return(pageEntity);
        }
Ejemplo n.º 8
0
        public static PageEntity <dynamic> GetPageDynamic <T>(this IDbConnection conn, int pageIndex, int pageSize, string where = null, object param = null, string returnFields = null, string orderBy = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);
            PageEntity <dynamic> pageEntity = new PageEntity <dynamic>();

            using (var reader = conn.QueryMultiple(builder.GetPageSql <T>(pageIndex, pageSize, where, returnFields, orderBy), param, tran, commandTimeout))
            {
                pageEntity.Total = reader.ReadFirstOrDefault <long>();
                if (pageEntity.Total > 0)
                {
                    pageEntity.Data = reader.Read <dynamic>();
                }
                else
                {
                    pageEntity.Data = Enumerable.Empty <dynamic>();
                }
            }
            return(pageEntity);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// for sqlserver insert identity
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <param name="updateFields"></param>
        /// <param name="update"></param>
        /// <returns></returns>
        public static int InsertIdentityOrUpdate <T>(this IDbConnection conn, T model, string updateFields = null, bool update = true, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var     builder   = BuilderFactory.GetBuilder(conn);
            int     effectRow = 0;
            dynamic total     = conn.ExecuteScalar <dynamic>(builder.GetExistsKeySql <T>(), model, tran, commandTimeout);

            if (total > 0)
            {
                if (update)
                {
                    effectRow += Update(conn, model, updateFields, tran, commandTimeout);
                }
            }
            else
            {
                effectRow += InsertIdentity(conn, model, tran, commandTimeout);
            }

            return(effectRow);
        }
Ejemplo n.º 10
0
        public static async Task <IEnumerable <dynamic> > GetAllDynamicAsync <T>(this IDbConnection conn, string returnFields = null, string orderBy = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.QueryAsync(builder.GetAllSql <T>(returnFields, orderBy), null, tran, commandTimeout));
        }
Ejemplo n.º 11
0
        public static async Task <long> GetTotalAsync <T>(this IDbConnection conn, string where = null, object param = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.ExecuteScalarAsync <long>(builder.GetTotalSql <T>(where), param, tran, commandTimeout));
        }
Ejemplo n.º 12
0
        public static async Task <IdType> GetSequenceNextAsync <IdType>(this IDbConnection conn, string sequence, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.ExecuteScalarAsync <IdType>(builder.GetSequenceNextSql(sequence), null, tran, commandTimeout));
        }
Ejemplo n.º 13
0
        public static async Task <IdType> GetIdentityAsync <IdType>(this IDbConnection conn, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.ExecuteScalarAsync <IdType>(builder.GetIdentitySql(), null, tran, commandTimeout));
        }
Ejemplo n.º 14
0
        public static async Task <int> DeleteAllAsync <T>(this IDbConnection conn, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.ExecuteAsync(builder.GetDeleteAllSql <T>(), null, tran, commandTimeout));
        }
Ejemplo n.º 15
0
        public static IdType GetSequenceCurrent <IdType>(this IDbConnection conn, string sequence, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(conn.ExecuteScalar <IdType>(builder.GetSequenceCurrentSql(sequence), null, tran, commandTimeout));
        }
Ejemplo n.º 16
0
        public static async Task <IEnumerable <dynamic> > GetByPageIndexDynamicAsync <T>(this IDbConnection conn, int pageIndex, int pageSize, string where = null, object param = null, string returnFields = null, string orderBy = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.QueryAsync(builder.GetByPageIndexSql <T>(pageIndex, pageSize, where, returnFields, orderBy), param, tran, commandTimeout));
        }
Ejemplo n.º 17
0
        public static async Task <dynamic> GetByWhereFirstDynamicAsync <T>(this IDbConnection conn, string where, object param = null, string returnFields = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.QueryFirstOrDefaultAsync <dynamic>(builder.GetByWhereFirstSql <T>(where, returnFields), param, tran, commandTimeout));
        }
Ejemplo n.º 18
0
        public static DataTable GetSchemaTable <T>(this IDbConnection conn, string returnFields = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(GetDataTable(conn, builder.GetSchemaTableSql <T>(returnFields), null, tran, commandTimeout));
        }
Ejemplo n.º 19
0
        public static IEnumerable <T> GetByPageIndex <T>(this IDbConnection conn, string query, int pageIndex, int pageSize, string where = null, object param = null, string returnFields = null, string orderBy = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(conn.Query <T>(builder.GetByPageIndexSql <T>(query, pageIndex, pageSize, where, returnFields, orderBy), param, tran, true, commandTimeout));
        }
Ejemplo n.º 20
0
        public static IEnumerable <dynamic> GetByWhereDynamic <T>(this IDbConnection conn, string where, object param = null, string returnFields = null, string orderBy = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(conn.Query(builder.GetByWhereSql <T>(where, returnFields, orderBy), param, tran, true, commandTimeout));
        }
Ejemplo n.º 21
0
        public static async Task <dynamic> GetByIdDynamicAsync <T>(this IDbConnection conn, object id, string returnFields = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.QueryFirstOrDefaultAsync <dynamic>(builder.GetByIdSql <T>(returnFields), new { id = id }, tran, commandTimeout));
        }
Ejemplo n.º 22
0
        public static int Delete <T>(this IDbConnection conn, object id, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(conn.Execute(builder.GetDeleteByIdSql <T>(), new { id = id }, tran, commandTimeout));
        }
Ejemplo n.º 23
0
        public static async Task <int> UpdateByWhereAsync <T>(this IDbConnection conn, T model, string where, string updateFields, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.ExecuteAsync(builder.GetUpdateByWhereSql <T>(where, updateFields), model, tran, commandTimeout));
        }
Ejemplo n.º 24
0
        public static IEnumerable <T> GetAll <T>(this IDbConnection conn, string returnFields = null, string orderBy = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(conn.Query <T>(builder.GetAllSql <T>(returnFields, orderBy), null, tran, true, commandTimeout));
        }
Ejemplo n.º 25
0
        public static async Task <IEnumerable <T> > GetBySkipTakeAsync <T>(this IDbConnection conn, int skip, int take, string where = null, object param = null, string returnFields = null, string orderBy = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.QueryAsync <T>(builder.GetBySkipTakeSql <T>(skip, take, where, returnFields, orderBy), param, tran, commandTimeout));
        }
Ejemplo n.º 26
0
        public static int Insert <T>(this IDbConnection conn, T model, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(conn.Execute(builder.GetInsertSql <T>(), model, tran, commandTimeout));
        }
Ejemplo n.º 27
0
        public static async Task <dynamic> InsertReturnIdAsync <T>(this IDbConnection conn, T model, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.ExecuteScalarAsync <dynamic>(builder.GetInsertReturnIdSql <T>(), model, tran, commandTimeout));
        }
Ejemplo n.º 28
0
        public static async Task <int> DeleteByWhereAsync <T>(this IDbConnection conn, string where, object param, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.ExecuteAsync(builder.GetDeleteByWhereSql <T>(where), param, tran, commandTimeout));
        }
Ejemplo n.º 29
0
        public static async Task <int> InsertIdentityAsync <T>(this IDbConnection conn, T model, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(await conn.ExecuteAsync(builder.GetInsertIdentitySql <T>(), model, tran, commandTimeout));
        }
Ejemplo n.º 30
0
        public static int Update <T>(this IDbConnection conn, T model, string updateFields = null, IDbTransaction tran = null, int?commandTimeout = null)
        {
            var builder = BuilderFactory.GetBuilder(conn);

            return(conn.Execute(builder.GetUpdateSql <T>(updateFields), model, tran, commandTimeout));
        }