示例#1
0
        public static void InsertCustomer(string customerId, string companyName, string city)
        {
            NorthwindEntities connection = new NorthwindEntities();

            using (connection)
            {
                var newCustomer = new Customer
                {
                    CustomerID = customerId,
                    CompanyName = companyName,
                    ContactName = null,
                    ContactTitle = null,
                    Address = null,
                    City = city,
                    Region = null,
                    PostalCode = null,
                    Country = null,
                    Phone = null,
                    Fax = null
                };

                connection.Customers.Add(newCustomer);
                connection.SaveChanges();
            }
        }
示例#2
0
        public static void ModifyCustomer(string customerId, string companyName, string city)
        {
            NorthwindEntities connection = new NorthwindEntities();

            using (connection)
            {
                var customerToModify = connection.Customers.Find(customerId);
                customerToModify.CompanyName = companyName;
                customerToModify.City = city;
                connection.SaveChanges();
            }
        }
示例#3
0
        public static void DeleteCustomer(string customerId)
        {
            NorthwindEntities connection = new NorthwindEntities();

            using (connection)
            {
                var customerToRemove = connection.Customers.Find(customerId);

                connection.Customers.Remove(customerToRemove);
                connection.SaveChanges();
            }
        }
示例#4
0
        private static void Main()
        {
            var firstEntity = new NorthwindEntities();
            var secondEntity = new NorthwindEntities();

            using (firstEntity)
            {
                using (secondEntity)
                {
                    var first = firstEntity.Customers.Find("ALFKI");
                    first.Region = "RE";

                    var second = secondEntity.Customers.Find("ALFKI");
                    second.Region = "ER";

                    firstEntity.SaveChanges();
                    secondEntity.SaveChanges();
                }
            }

            Console.WriteLine("Done");
        }