Esempio n. 1
0
 public static void PlaceOrder()
 {
     Lock();
     try
     {
         using (var ctx = new FooDBContext())
         {
             Customer customer = ctx.Customers
                                 .Include(c => c.Orders)
                                 .First();
             customer.Orders.Add(new Order()
             {
                 Whatever = "cookies"
             });
             customer.OrdersCount += 1;
             ctx.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("{0}: {1}", e.Message, e.StackTrace);
     }
     finally
     {
         Unlock();
     }
 }
Esempio n. 2
0
 static FooDBContext()
 {
     using (var ctx = new FooDBContext())
     {
         if (ctx.Database.GetPendingMigrations().Count() > 0)
         {
             ctx.Database.Migrate();
         }
         if (ctx.Customers.Count() == 0)
         {
             ctx.Customers.Add(new Customer()
             {
                 Name        = "kevin",
                 OrdersCount = 0
             });
             ctx.SaveChanges();
         }
     }
 }