/// <summary> /// Saves books. /// </summary> /// <param name="books"></param> /// <returns></returns> public static DbContextOptions <BookStoreContext> SeedWith(this DbContextOptions <BookStoreContext> source, IEnumerable <Book> books) { using var context = source.BuildDbContext(); context.Books.AddRange(books); context.SaveChanges(); return(source); }
/// <summary> /// Ensures deletion and then creation of the connected db. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <returns></returns> public static DbContextOptions <T> EnsureDb <T>(this DbContextOptions <T> source) where T : DbContext { using var context = source.BuildDbContext(); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); return(source); }