public static void Initialize(IServiceProvider serviceProvider) { using (var context = new MSAContext( serviceProvider.GetRequiredService < DbContextOptions <MSAContext> >())) { if (context.User.Any()) { return; // DB has been seeded } var users = UserGenerator.GenerateUsers(); foreach (User user in users) { context.User.AddRange(user); } Console.WriteLine("DB seeded."); context.SaveChanges(); } }
public void Save() { context.SaveChanges(); }