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(); } } }
public Repository(TouristPlaceContext context) { _context = context; entities = context.Set <T>(); }