private static void AddDataRec4() { using (var context = new EFRecipesEntities2()) { var order = new Order() { OrderId = 2, OrderDate = new DateTime(2010, 1, 18) }; var item = new Item { SKU = 1229, Description = "Backpack", Price = 29.97M }; var oi = new OrderItem { Order = order, Item = item, Count = 1 }; context.OrderItems.Add(oi); item = new Item { SKU = 2229, Description = "Water Filter", Price = 13.97M }; oi = new OrderItem { Order = order, Item = item, Count = 3 }; context.OrderItems.Add(oi); context.SaveChanges(); } }
private static void ViewData4() { using (var context = new EFRecipesEntities2()) { foreach (var order in context.Orders) { Console.WriteLine("Order # {0}, ordered on {1}", order.OrderId.ToString(), order.OrderDate.ToShortDateString()); Console.WriteLine("SKU\tDescription\tQty\tPrice"); Console.WriteLine("---\t-----------\t---\t-----"); foreach (var oi in order.OrderItems) { Console.WriteLine("{0}\t{1}\t{2}\t{3}", oi.Item.SKU, oi.Item.Description, oi.Count.ToString(), oi.Item.Price.ToString("C")); } } } }