public static void Initialize(IServiceProvider serviceProvider) { using (var context = new CityGuideDBContext( serviceProvider.GetRequiredService <DbContextOptions <CityGuideDBContext> >())) { // Look for any points of interest already in database if (context.PointsOfInterest.Any()) { return; // Database has been seeded } context.PointsOfInterest.AddRange( new PointOfInterest() { Id = 1, Name = "Monastery of Jerónimos" }, new PointOfInterest() { Id = 2, Name = "Belém Tower" }); context.SaveChanges(); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new CityGuideDBContext( serviceProvider.GetRequiredService <DbContextOptions <CityGuideDBContext> >())) { // Look for any points of interest already in database if (context.PointsOfInterest.Any()) { return; // Database has been seeded } for (int i = 1; i <= 100; i++) { context.PointsOfInterest.Add(new PointOfInterest() { Id = i }); } context.SaveChanges(); } }
public PointOfInterestController(CityGuideDBContext context) { _context = context; }