コード例 #1
0
 public void Insert(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     entities.Add(entity);
     _context.SaveChanges();
 }
コード例 #2
0
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using (var context = new TouristPlaceContext(serviceProvider.GetRequiredService <DbContextOptions <TouristPlaceContext> >()))
     {
         if (!context.UserLogIn.Any())
         {
             context.UserLogIn.AddRange(
                 new UserLogIn
             {
                 UserId   = "a",
                 Password = "******"
             },
                 new UserLogIn
             {
                 UserId   = "toha",
                 Password = "******"
             }
                 );
             context.SaveChanges();
         }
         if (!context.Country.Any())
         {
             context.Country.AddRange(
                 new Country
             {
                 Name = "Bangladesh"
             },
                 new Country
             {
                 Name = "India"
             },
                 new Country
             {
                 Name = "Nepal"
             },
                 new Country
             {
                 Name = "Thailand"
             },
                 new Country
             {
                 Name = "USA"
             }
                 );
             context.SaveChanges();
         }
     }
 }