static void Main(string[] args) { // task - 7 - https://msdn.microsoft.com/en-us/data/jj592904.aspx for (int i = 0; i < 3; i++) { var firstConection = new NorthwindEntities(); var secondConection = new NorthwindEntities(); Console.WriteLine(); var firstCustomer = firstConection.Customers.Find("TELER"); var secondCustomer = secondConection.Customers.Find("TELER"); Console.WriteLine("Name from first connection: " + firstCustomer.CompanyName); Console.WriteLine("Name from second connection: " + secondCustomer.CompanyName); firstCustomer.CompanyName = "TELERIK 1"; secondCustomer.CompanyName = "TELERIK 2"; secondConection.SaveChanges(); firstConection.SaveChanges(); var result = new NorthwindEntities().Customers.Find("TELER"); Console.WriteLine("Final company name {0}", result.CompanyName); Console.WriteLine(); } }
public static void DeleteCustomer(string customerId) { var northwind = new NorthwindEntities(); var customer = GetCustomerById(northwind, customerId); northwind.Customers.Remove(customer); northwind.SaveChanges(); }
public static void ModifyContactName(string customerId, string contactName) { var northwind = new NorthwindEntities(); var customer = GetCustomerById(northwind, customerId); customer.ContactName = contactName; northwind.SaveChanges(); }
public static void Main() { var firstConection = new NorthwindEntities(); var secondConection = new NorthwindEntities(); Console.WriteLine(); var firstCustomer = firstConection.Customers.First(); var secondCustomer = secondConection.Customers.First(); Console.WriteLine("Name from first connection: " + firstCustomer.CompanyName); Console.WriteLine("Name from second connection: " + secondCustomer.CompanyName); firstCustomer.CompanyName = "Google"; secondCustomer.CompanyName = "Microsoft"; //// What will happen at SaveChanges()? - second company name change will be implemented //// How to deal with it? - either by using a single connection, or if not applicable - by introduction of transactions isolation levels firstConection.SaveChanges(); secondConection.SaveChanges(); var result = new NorthwindEntities().Customers.First(); Console.WriteLine("Final company name {0}", result.CompanyName); Console.WriteLine(); }
public static void DeleteCustomer(string customerID) { using (var northwindEntities = new NorthwindEntities()) { Customer customer = GetCustomerById(northwindEntities, customerID); northwindEntities.Customers.Remove(customer); northwindEntities.SaveChanges(); } }
public static void ModifyCustomerCompanyName(string customerID, string newCompanyName) { using (var northwindEntities = new NorthwindEntities()) { var customer = GetCustomerById(northwindEntities, customerID); customer.CompanyName = newCompanyName; northwindEntities.SaveChanges(); } }
public static string InsertNewCustomer(Customer customer) { if (customer == null) { throw new ArgumentNullException("Customer cannot be null"); } using (var northwindEntities = new NorthwindEntities()) { northwindEntities.Customers.Add(customer); northwindEntities.SaveChanges(); return customer.CustomerID; } }
public static void Main() { var northwind = new NorthwindEntities(); CustomerController.AddCustomer("TELER", "Telerik", "Qsdcds Fvdvsdv", "eqrwrqwer", "asfasfsdff", "Qsadsad", "dsf", "1234", "Qwerwer", "+12345678", "+12345678"); CustomerController.ModifyCompanyName("TELER", "Telerik, Qwewer"); CustomerController.DeleteCustomer("TELER"); northwind.SaveChanges(); Console.WriteLine("Customers who shipped to Canada in 1997: "); FindCustomersByOrdersYearAndCountry(northwind, 1997, "Canada"); FindCustomersByOrdersYearAndCountryWithNativeSql(northwind, 1997, "Canada"); Console.WriteLine("Orders shipped to Sao Paulo region between 18 and 19 years ago."); FindSalesByRegionAndTimePeriod(northwind, "SP", DateTime.Now.AddYears(-19), DateTime.Now.AddYears(-18)); }
public static string AddCustomer(string customerId, string companyName, string contactName, string contactTitle, string address, string city, string region, string postalCode, string country, string phone, string fax) { var northwind = new NorthwindEntities(); var customer = new Customer() { CustomerID = customerId, CompanyName = companyName, ContactName = contactName, ContactTitle = contactTitle, Address = address, City = city, Region = region, PostalCode = postalCode, Country = country, Phone = phone, Fax = fax, }; northwind.Customers.Add(customer); northwind.SaveChanges(); return customer.CustomerID; }