示例#1
0
 private static void Initialize()
 {
     var initializer = new MigrateDatabaseToLatestVersion<Context, DbConfig>();
     Database.SetInitializer(initializer);
     using (var context = new Context())
     {
         context.Database.Initialize(force: true);
         context.SaveChanges();
     }
 }
示例#2
0
        private static void ClearDb()
        {
            using (var context = new Context())
            {
                foreach (var itinerary in context.Itineraries.ToList())
                    context.Itineraries.Remove(itinerary);

                foreach (var user in context.Users.Include(u => u.Address).ToList())
                    context.Users.Remove(user);

                context.SaveChanges();
            }
        }
示例#3
0
        private static void InsertData()
        {
            var user = new User
                {
                    Name = "John",
                    Address = new Address
                        {
                            Street = "Victoria Avenue"
                        }
                };

            var itinerary = new Itinerary
                {
                    Addresses = new List<Address> { user.Address }
                };

            using (var context = new Context())
            {
                context.Users.Add(user);
                context.Itineraries.Add(itinerary);
                context.SaveChanges();
            }
        }