public void MysqlExecuteScalarTra() { MyDapperPower.DbConnection("server=localhost;port=3306;user id=root;password=Aa82078542;database=testmysql;SslMode=none", "mysql", "mysql"); UserLocalDAL userLocalDAL = new UserLocalDAL(); var commandText = $"select status from {EntityHelper.CallName<UserLocal>()} where id = @id"; var commandText2 = $"update {EntityHelper.CallName<UserLocal>()} set status = 5 where id = @id"; using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { using (var connection = userLocalDAL.Connection) { int id = 22; var result1 = userLocalDAL.ExecuteScalar <int>(connection, commandText2, new { id }); var result2 = userLocalDAL.ExecuteScalar <int>(connection, commandText, new { id }); Assert.Equal(5, result2); } } }
public void MysqlExecuteScalar() { MyDapperPower.DbConnection("server=localhost;port=3306;user id=root;password=Aa82078542;database=testmysql;SslMode=none", "mysql", "mysql"); UserLocalDAL userLocalDAL = new UserLocalDAL(); var commandText = $"select * from {EntityHelper.CallName<UserLocal>()} where id = @id"; int id = 21; var result = userLocalDAL.ExecuteScalar <int>(commandText, new { id }); Assert.Equal(id, result); }