Пример #1
0
        private static void ModifyCustomer()
        {
            using (var dbContext = new NorthwindEntities())
            {
                var luckyCustomer = dbContext.Customers.FirstOrDefault();
                luckyCustomer.Country = "Bulgaria";
                dbContext.SaveChanges();
            }

            Console.WriteLine("The customer was modified successfully");
        }
Пример #2
0
        private static void DeleteCustomer()
        {
            using (var dbContext = new NorthwindEntities())
            {
                var unluckyCustomer = dbContext.Customers.Where(c => c.CustomerID == "100").FirstOrDefault();
                dbContext.Customers.Remove(unluckyCustomer);
                dbContext.SaveChanges();
            }

            Console.WriteLine("The customer was deleted successfully");
        }
Пример #3
0
        private static void InsertCustomer()
        {
            using (var dbContext = new NorthwindEntities())
            {
                dbContext.Customers.Add(new Customer()
                {
                    CompanyName = "Fake company",
                    CustomerID = "100"
                });

                dbContext.SaveChanges();
            }

            Console.WriteLine("The customer was added successfully");
        }
Пример #4
0
        public static void Main(string[] args)
        {
            var firstDbContext = new NorthwindEntities();
            var secondDbContext = new NorthwindEntities();

            var randomRegion = firstDbContext.Regions.FirstOrDefault();
            var anotherRandomRegion = secondDbContext.Regions.FirstOrDefault();

            randomRegion.RegionDescription = "Changed Description 1";
            anotherRandomRegion.RegionDescription = "changed Description 2";

            firstDbContext.SaveChanges();
            secondDbContext.SaveChanges();

            firstDbContext.Dispose();
            secondDbContext.Dispose();

            var thirdDbContext = new NorthwindEntities();
            var actualRegion = thirdDbContext.Regions.FirstOrDefault();
            Console.WriteLine(actualRegion.RegionDescription);
        }