static void RunExample() { // bad order date using (var context = new EFRecipesEntities()) { var customer = new Customer { Name = "Phil Marlowe" }; var order = new SalesOrder { OrderDate = DateTime.Parse("3/12/18"), Amount = 19.95M, Status = "Approved", ShippingCharge = 3.95M, Customer = customer }; context.Customers.AddObject(customer); try { context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } // order shipped before it was ordered using (var context = new EFRecipesEntities()) { var customer = new Customer { Name = "Phil Marlowe" }; var order = new SalesOrder { OrderDate = DateTime.Parse("3/12/10"), Amount = 19.95M, Status = "Approved", ShippingCharge = 3.95M, Customer = customer }; context.Customers.AddObject(customer); context.SaveChanges(); try { order.Shipped = true; order.ShippedDate = DateTime.Parse("3/10/10"); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } // order shipped, but not approved using (var context = new EFRecipesEntities()) { var customer = new Customer { Name = "Phil Marlowe" }; var order = new SalesOrder { OrderDate = DateTime.Parse("3/12/10"), Amount = 19.95M, Status = "Pending", ShippingCharge = 3.95M, Customer = customer }; context.Customers.AddObject(customer); context.SaveChanges(); try { order.Shipped = true; order.ShippedDate = DateTime.Parse("3/13/10"); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } // order over $5,000 and shipping not free using (var context = new EFRecipesEntities()) { var customer = new Customer { Name = "Phil Marlowe" }; var order = new SalesOrder { OrderDate = DateTime.Parse("3/12/10"), Amount = 6200M, Status = "Approved", ShippingCharge = 59.95M, Customer = customer }; context.Customers.AddObject(customer); context.SaveChanges(); try { order.Shipped = true; order.ShippedDate = DateTime.Parse("3/13/10"); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } // order deleted after it was shipped using (var context = new EFRecipesEntities()) { var customer = new Customer { Name = "Phil Marlowe" }; var order = new SalesOrder { OrderDate = DateTime.Parse("3/12/10"), Amount = 19.95M, Status = "Approved", ShippingCharge = 3.95M, Customer = customer }; context.Customers.AddObject(customer); context.SaveChanges(); order.Shipped = true; order.ShippedDate = DateTime.Parse("3/13/10"); context.SaveChanges(); try { context.DeleteObject(order); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine("Press <enter> to continue..."); Console.ReadLine(); }
/// <summary> /// Deprecated Method for adding a new object to the SalesOrders EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSalesOrders(SalesOrder salesOrder) { base.AddObject("SalesOrders", salesOrder); }