public static void Initialize(IServiceProvider serviceProvider) { using (var context = new MvcTitleContext( serviceProvider.GetRequiredService < DbContextOptions <MvcTitleContext> >())) { if (context.User.Any()) { return; } var user = new User { Name = "Ryan", Email = "*****@*****.**" }; context.User.Add(user); context.SaveChanges(); if (context.Title.Any()) { return; } var csvImporter = new CsvImporter(); csvImporter.ImportTitles(context); } }
public void ImportTitles(MvcTitleContext context) { using (var reader = new StreamReader(@"C:\Users\Ryan\source\repos\MvcTitle\Models\netflix_titles.csv")) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { csv.Configuration.RegisterClassMap <TitleMap>(); var titles = csv.GetRecords <Title>(); foreach (var title in titles) { context.Title.Add(title); } context.SaveChanges(); } }