Ejemplo n.º 1
0
        public void TestUpdateOperationAnsi()
        {
            var connection = new MaxDBConnection(ConfigurationManager.ConnectionStrings["maxdb"].ConnectionString);

            connection.Open();

            var trans = connection.BeginTransaction();

            using (var conn = connection)
            {
                IScriptBuilder builder = conn.GetScriptBuild();

                var cliente = new Cliente()
                {
                    Id = 1, Nome = "Moisés", Ativo = true
                };

                var createTableScript = builder.GetCreateTableCommand <Cliente>();
                builder.Execute(createTableScript, conn, trans);

                conn.Insert <Cliente>(cliente, true, trans);
                cliente.Nome = "Paul";
                conn.Update(cliente);

                cliente.Nome = "John Lennon";
                conn.Execute("drop table \"Cliente\"");
                //conn.Execute("drop sequence \"sequence_cliente_id\"");
            }
        }
Ejemplo n.º 2
0
        public void TestSelectOperationAnsi()
        {
            var connection = new MaxDBConnection(ConfigurationManager.ConnectionStrings["maxdb"].ConnectionString);

            connection.Open();

            using (var scope = new TransactionScope())
            {
                using (var conn = connection)
                {
                    IScriptBuilder builder = conn.GetScriptBuild();

                    var cliente = new Cliente()
                    {
                        Id = 1, Nome = "Moisés", Ativo = true
                    };
                    var cliente2 = new Cliente()
                    {
                        Id = 2, Nome = "José", Ativo = true
                    };

                    var createTableScript = builder.GetCreateTableCommand <Cliente>();

                    var insertScript1 = builder.GetInsertCommand <Cliente>(cliente, true);
                    var insertScript2 = builder.GetInsertCommand <Cliente>(cliente2, true);

                    builder.Execute(createTableScript, conn);
                    builder.Execute(insertScript1, conn);
                    builder.Execute(insertScript2, conn);

                    var clientes = conn.GetAll <Cliente>();
                    Assert.AreEqual(2, clientes.Count());
                    Assert.AreEqual("Moisés", clientes.ToList()[0].Nome);
                    Assert.AreEqual("José", clientes.ToList()[1].Nome);

                    conn.Execute("drop table \"Cliente\"");
                }
            }
        }