public void Insert()
 {
     try
     {
         using (var context = new ContextClass1())
         {
             var product = new Product
             {
                 ProductName  = "Laptop",
                 ProductPrice = 30000
             };
             context.Productss.Add(product);
             context.SaveChanges();
             Console.WriteLine("Record inserted sucessfully ");
         }
     }
     catch (Exception)
     {
         Console.WriteLine("Record  is not  inserted suessfully");
     }
 }
Пример #2
0
        public void Excute()
        {
            try
            {
                using (var context = new ContextClass1())
                {
                    var order = new Order();

                    Console.Write("Enter OrderName:");
                    order.OrderName = Console.ReadLine();
                    Console.Write("Enter  Orderprice : ");
                    order.OrderPrice = int.Parse(Console.ReadLine());
                    Console.Write("Enter the Product id:");
                    order.ProductId = Convert.ToInt32(Console.ReadLine());
                    context.Orders.Add(order);
                    context.SaveChanges();
                    Console.WriteLine("Orders record inserted successfully.");
                }
            }
            catch
            {
                Console.WriteLine("oops somerthing went wrong");
            }
        }