예제 #1
0
 /// <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);
 }
예제 #2
0
 /// <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);
 }