Ejemplo n.º 1
0
        //删除一个用户及指定的日志
        public void DeleteNoteAndUser(string Name)
        {
            using (MySqlConnection conn = DbContextFactory.GetMySqlConnection())
                using (IDbTransaction tx = conn.BeginTransaction())
                {
                    try
                    {
                        string sql1 = "select * from t_users where Name=@Name";
                        User   user = DapperHelper <User> .GetEntity(sql1, new { Name = Name });

                        string sql2 = "delete from t_users where Id=@Id";
                        DapperHelper <User> .Execute(sql2, user);

                        string sql3 = "delete from t_notes where User_Id=@User_Id";
                        DapperHelper <Note> .Execute(sql3, new { User_Id = user.Id });

                        tx.Commit();
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
        }
Ejemplo n.º 2
0
 //增删改操作(批量)
 public int Execute(string sql, object obj)
 {
     return(DapperHelper <T> .Execute(sql, obj));
 }
Ejemplo n.º 3
0
 public int Execute(string sql, T t)
 {
     return(DapperHelper <T> .Execute(sql, t));
 }