コード例 #1
0
        public static void DeleteCustomerById(string id)
        {
            var db = new NorthwindEntities();

            using (db)
            {
                Customer customer = db.Customers.Where(c => c.CustomerID == id).FirstOrDefault();
                db.Customers.Remove(customer);

                db.SaveChanges();
            }
        }
コード例 #2
0
ファイル: EntryPoint.cs プロジェクト: VDGone/TelerikAcademy-1
        public static void Main()
        {
            NorthwindEntities dbOne = new NorthwindEntities();
            NorthwindEntities dbTwo = new NorthwindEntities();

            dbOne.Database.Connection.Open();

            Employee employee = new Employee()
            {
                LastName = "Minkov",
                FirstName = "Doncho",
                Title = "Dev Manager",
                TitleOfCourtesy = "Mr",
                BirthDate = new DateTime(1990, 08, 08),
                HireDate = new DateTime(2009, 05, 05),
                Address = "str.Alexander Malinov 31",
                City = "Sofia",
                PostalCode = "1001",
                Country = "Bulgaria"
            };

            dbOne.Employees.Add(employee);
            dbOne.SaveChanges();

            dbTwo.Database.Connection.Open();

            Employee employeeToUpdate = dbTwo.Employees
                .Where(e => e.City.Equals("Sofia"))
                .FirstOrDefault();

            employeeToUpdate.City = "London";
            employeeToUpdate.Address = "Downing Street 10";
            dbTwo.SaveChanges();

            dbOne.Database.Connection.Close();
            dbTwo.Database.Connection.Close();
        }
コード例 #3
0
        public static void InsertCustomer(
            string id,
            string commpanyName,
            string contactName,
            string contactTitle,
            string address,
            string city,
            string region,
            string postalCode,
            string country,
            string phone,
            string fax)
        {
            var db = new NorthwindEntities();

            using (db)
            {
                Customer customer = new Customer()
                {
                    CustomerID = id,
                    CompanyName = commpanyName,
                    ContactName = contactName,
                    ContactTitle = contactTitle,
                    Address = address,
                    City = city,
                    Region = region,
                    PostalCode = postalCode,
                    Country = country,
                    Phone = phone,
                    Fax = fax
                };

                db.Customers.Add(customer);
                db.SaveChanges();
            }
        }
コード例 #4
0
        public static void UpdateCustomer(
           string id,
           string commpanyName,
           string contactName,
           string contactTitle,
           string address,
           string city,
           string region,
           string postalCode,
           string country,
           string phone,
           string fax)
        {
            var db = new NorthwindEntities();

            using (db)
            {
                Customer customer = db.Customers.Where(c => c.CustomerID == id).FirstOrDefault();

                customer.CustomerID = id;
                customer.CompanyName = commpanyName;
                customer.ContactName = contactName;
                customer.ContactTitle = contactTitle;
                customer.Address = address;
                customer.City = city;
                customer.Region = region;
                customer.PostalCode = postalCode;
                customer.Country = country;
                customer.Phone = phone;
                customer.Fax = fax;

                db.SaveChanges();
            }
        }