public void SimpleDeleteRowByParameter()
        {
            //Make sure the table exists
            var createTableSql = "CREATE TABLE IF NOT EXISTS Toys ( `Id` INT NOT NULL AUTO_INCREMENT, `SupplierId` INT NOT NULL, `Name` varchar(100) NOT NULL,`MinAge` int NOT NULL, CONSTRAINT PK_Toys PRIMARY KEY (Id)) ENGINE=InnoDB;";

            if (st.conn.State != ConnectionState.Open)
            {
                st.conn.Open();
            }

            MySqlHelper.ExecuteNonQuery(st.conn, createTableSql);
            MySqlHelper.ExecuteNonQuery(st.conn, "DELETE FROM Toys");
            MySqlHelper.ExecuteNonQuery(st.conn, "INSERT INTO Toys VALUES (1, 3, 'Slinky', 2), (2, 2, 'Rubiks Cube', 5), (3, 1, 'Lincoln Logs', 3), (4, 4, 'Legos', 4)");


            using (testEntities context = new testEntities())
            {
                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM toys WHERE minage=3", st.conn);
                DataTable        dt = new DataTable();
                da.Fill(dt);
                Assert.True(dt.Rows.Count > 0);

                ObjectQuery <Toy> toys = context.Toys.Where("it.MinAge = @age", new ObjectParameter("age", 3));
                foreach (Toy t in toys)
                {
                    context.DeleteObject(t);
                }
                context.SaveChanges();

                dt.Clear();
                da.Fill(dt);
                Assert.Equal(0, dt.Rows.Count);
            }
        }
예제 #2
0
        public void Delete()
        {
            using (testEntities context = new testEntities())
            {
                foreach (Book b in context.Books)
                {
                    context.DeleteObject(b);
                }
                context.SaveChanges();
            }

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Books", st.conn);
            DataTable        dt = new DataTable();

            da.Fill(dt);
            Assert.Equal(0, dt.Rows.Count);
        }
        public void SimpleDeleteAllRows()
        {
            using (testEntities context = new testEntities())
            {
                foreach (Toy t in context.Toys)
                {
                    context.DeleteObject(t);
                }
                context.SaveChanges();

                EntityConnection ec = context.Connection as EntityConnection;
                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM toys",
                                                           (MySqlConnection)ec.StoreConnection);
                DataTable dt = new DataTable();
                da.Fill(dt);
                Assert.AreEqual(0, dt.Rows.Count);
            }
        }
        public void SimpleDeleteRowByParameter()
        {
            using (testEntities context = new testEntities())
            {
                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM toys WHERE minage=3", conn);
                DataTable        dt = new DataTable();
                da.Fill(dt);
                Assert.IsTrue(dt.Rows.Count > 0);

                ObjectQuery <Toy> toys = context.Toys.Where("it.MinAge = @age", new ObjectParameter("age", 3));
                foreach (Toy t in toys)
                {
                    context.DeleteObject(t);
                }
                context.SaveChanges();

                dt.Clear();
                da.Fill(dt);
                Assert.AreEqual(0, dt.Rows.Count);
            }
        }