public static async Task SetOrdersAsync(List <string> names) { using (var db = new EF6_PhoneStoreDB()) { db.Orders.AddRange( new List <Order> { new Order { Customer = names[0], Date = DateTime.Now, Phones = (from p in db.Phones where p.Id == 1 || p.Id == 2 select p).ToList() }, new Order { Customer = names[1], Date = DateTime.Now, Phones = (from p in db.Phones where p.Id == 3 || p.Id == 4 select p).ToList() } }); await db.SaveChangesAsync(); } }
public static async Task SetOrdersAsync(List<string> names) { using (var db = new EF6_PhoneStoreDB()) { db.Orders.AddRange( new List<Order> { new Order { Customer = names[0], Date = DateTime.Now, Phones = (from p in db.Phones where p.Id == 1 || p.Id == 2 select p).ToList() }, new Order { Customer = names[1], Date = DateTime.Now, Phones = (from p in db.Phones where p.Id == 3 || p.Id == 4 select p).ToList() } }); await db.SaveChangesAsync(); } }
static void Main(string[] args) { using (var db = new EF6_PhoneStoreDB()) { Task task = OperationsAsync.SetOrdersAsync(new List<string> { "Nick", "Fred" }); task.Wait(); task = OperationsAsync.GetOrderAsync(); task.Wait(); Console.ReadKey(); } }
static void Main(string[] args) { using (var db = new EF6_PhoneStoreDB()) { Task task = OperationsAsync.SetOrdersAsync(new List <string> { "Nick", "Fred" }); task.Wait(); task = OperationsAsync.GetOrderAsync(); task.Wait(); Console.ReadKey(); } }
public static async Task GetOrderAsync() { using (var db = new EF6_PhoneStoreDB()) { await db.Orders.ForEachAsync(p => { Console.WriteLine("{0} {1}", p.Customer, p.Date); foreach (var item in db.Phones) { if (item.OrderId == p.Id) { Console.WriteLine(" {0} {1}", item.Company, item.Model); } } } ); } }