Example #1
0
        static void Main(string[] args)
        {
            using (NORTHWINDEntities ctx = new NORTHWINDEntities())
            {
                Console.WriteLine("\nGet product...");
                Console.ReadLine();
                Product chai = ctx.Products.Find(1);
                Display(ctx, chai);

                Console.WriteLine("\nUpdate price...");
                Console.ReadLine();
                ++chai.UnitPrice;
                Display(ctx, chai);

                Console.WriteLine("\nCreate new product...");
                Console.ReadLine();
                Product kahula = new Product() { ProductName = "Kahula Coffee", UnitPrice = 10 };
                Display(ctx, kahula);

                Console.WriteLine("\nAdd new product tocontext...");
                Console.ReadLine();
                ctx.Products.Add(kahula);
                Display(ctx, kahula);

                Console.WriteLine("\nSave changes....");
                Console.ReadLine();
                ctx.SaveChanges();
                Display(ctx, chai);
                Display(ctx, kahula);

                Console.WriteLine("\nDelete kahula...");
                Console.ReadLine();
                ctx.Products.Remove(kahula);
                Display(ctx, kahula);

                Console.WriteLine("\nSave changes....");
                Console.ReadLine();
                ctx.SaveChanges();
                Display(ctx, kahula);

                Console.WriteLine("Finished");
                Console.ReadLine();
            }
        }