Example #1
0
 private static void Update()
 {
     using (var context = new udemyContext())
     {
         Customers fromEf = context.Set <Customers>().Find(6);
         fromEf.Name = "updated";
         context.SaveChanges();
     }
 }
Example #2
0
 private static void Delete()
 {
     using (var context = new udemyContext())
     {
         Customers updated = context.Set <Customers>()
                             .Where(c => c.Id == 6)
                             .FirstOrDefault();
         context.Remove(updated);
         context.SaveChanges();
     }
 }
Example #3
0
        private static void Insert()
        {
            // INSERT INTO Customers (name, lastname) VALUES ('customer', 'from ef');
            var customer = new Customers
            {
                Name     = "customer",
                Lastname = "from ef"
            };

            System.Console.WriteLine(customer);
            using (var context = new udemyContext())
            {
                context.Add(customer);
                //unit of work:
                context.SaveChanges();
            }
        }