示例#1
0
 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();
     }
 }
示例#2
0
 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();
     }
 }
示例#3
0
        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();
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
 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);
                 }
             }
         }
                                      );
     }
 }
示例#6
0
 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);
                 }
                 
             }
         }
         );
     }
 }