示例#1
0
        public static void AddMemeber(Member m)
        {
            var context = new CommereceDBContext();

            context.Members.Add(m);

            context.SaveChanges();
        }
示例#2
0
        public static void Update(Product p)
        {
            var context = new CommereceDBContext();

            //Tell EF this product has only been modified
            //It's already in the database
            context.Entry(p).State = EntityState.Modified;
            //Send Update query to the DB
            context.SaveChanges();
        }
示例#3
0
        //missisng something

        public static void DeleteProduct(int id)
        {
            var context = new CommereceDBContext();
            //makes Ef recognize that p came from the DB.
            Product p = context.Products.Find(id);

            //marks p for deletion
            context.Products.Remove(p);
            //sends the above query to the DB
            context.SaveChanges();
        }
示例#4
0
        // step 1. create a instance of the db
        // step 2. Add a pending object
        // step 3. execute the add using saveChanges();



        /// <summary>
        /// adds a product to the database using entity syntax.           //////////////////// REFERENCE
        /// </summary>
        /// <param name="p"></param>
        public static void AddProduct(Product p)
        {
            //1.
            //Create instance of DBContext class.
            //context is referencingthe DB
            CommereceDBContext context = new CommereceDBContext();

            //2.
            //Prepare insert statement
            //tells entity you want to add a product (p) to the database dosnt add it.
            context.Products.Add(p);
            // 3.
            //Execute pending insert    //the pending insert is what was done above with context.Products.Add(p)
            context.SaveChanges();
        }