コード例 #1
0
        public static int Delete <T>(this IDbConnection db, Expression <Func <T, bool> > deleteExpression, IDbTransaction trans = null, int?commandTimeout = null)
        {
            if (deleteExpression == null)
            {
                throw new Exception("delete expression is null!");
            }

            var sqllam = new SqlExp <T>(db.GetAdapter());


            sqllam = sqllam.Delete(deleteExpression);
            var sqlString = sqllam.SqlString;

            try
            {
                DebuggingSqlString(sqlString);
                return(db.Execute(sqlString, sqllam.Parameters, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                DebuggingException(ex, sqlString);
                throw new DapperLamException(ex.Message, ex, sqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }
コード例 #2
0
        public static int DeleteList <T>(this IDbConnection db, IEnumerable <T> engityList, IDbTransaction trans = null, int?commandTimeout = null)
        {
            if (!engityList.Any())
            {
                return(0);
            }

            var sqllam = new SqlExp <T>(db.GetAdapter());


            sqllam = sqllam.Delete();
            var sqlString = sqllam.SqlString;

            try
            {
                DebuggingSqlString(sqlString);
                return(db.Execute(sqlString, engityList, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                DebuggingException(ex, sqlString);
                throw new DapperLamException(ex.Message, ex, sqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }
コード例 #3
0
        public static Task <int> DeleteListAsync <T>(this IDbConnection con, IEnumerable <T> entityList,
                                                     IDbTransaction trans = null,
                                                     int?commandTimeout   = null)
        {
            var db = con;

            if (trans != null)
            {
                db = trans.Connection;
            }
            if (!entityList.Any())
            {
                return(Task.FromResult(0));
            }

            var sqllam = new SqlExp <T>(db.GetAdapter());


            sqllam = sqllam.Delete();
            var sqlString = sqllam.SqlString;

            try
            {
                DebuggingSqlString(sqlString);
                return(db.ExecuteAsync(sqlString, entityList, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                DebuggingException(ex, sqlString);
                throw new DapperLamException(ex.Message, ex, sqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }
コード例 #4
0
        public static Task <int> DeleteAsync <T>(this IDbConnection con, Action <SqlExp <T> > action,
                                                 IDbTransaction trans = null,
                                                 int?commandTimeout   = null)
        {
            var db = con;

            if (trans != null)
            {
                db = trans.Connection;
            }
            var sqllam = new SqlExp <T>(db.GetAdapter());

            sqllam = sqllam.Delete();

            action?.Invoke(sqllam);
            var sqlString = sqllam.SqlString;

            try
            {
                DebuggingSqlString(sqlString);
                return(db.ExecuteAsync(sqlString, sqllam.Parameters, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                DebuggingException(ex, sqlString);
                throw new DapperLamException(ex.Message, ex, sqllam.SqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }
コード例 #5
0
        public static int Delete <T>(this IDbConnection db, Action <SqlExp <T> > action, IDbTransaction trans = null, int?commandTimeout = null)
        {
            var sqllam = new SqlExp <T>(db.GetAdapter());

            sqllam = sqllam.Delete();

            action?.Invoke(sqllam);

            try
            {
                return(db.Execute(sqllam.SqlString, sqllam.Parameters, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                    Debug.WriteLine(sqllam.SqlString);
                }

                Console.WriteLine(ex.Message + ex.StackTrace);
                Console.WriteLine(sqllam.SqlString);
                throw new DapperLamException(ex.Message, ex, sqllam.SqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }
コード例 #6
0
        public static int Delete <T>(this IDbConnection con, T entity, IDbTransaction trans = null, int?commandTimeout = null)
        {
            var db     = trans == null ? con : trans.Connection;
            var sqllam = new SqlExp <T>(db.GetAdapter());


            sqllam = sqllam.Delete();
            var sqlString = sqllam.SqlString;

            try
            {
                DebuggingSqlString(sqlString);
                return(db.Execute(sqlString, entity, trans, commandTimeout, CommandType.Text));
            }
            catch (Exception ex)
            {
                DebuggingException(ex, sqlString);
                throw new DapperLamException(ex.Message, ex, sqlString)
                      {
                          Parameters = sqllam.Parameters
                      };
            }
        }