Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. using (IServiceScope scope = host.Services.CreateScope())
  2. {
  3. AppDbContext dbCtx = scope.ServiceProvider.GetRequiredService<AppDbContext>();
  4. dbCtx.Database.Migrate();
  5. if (!dbCtx.Products.Any())
  6. {
  7. dbCtx.Products.Add(
  8. new Product
  9. {
  10. Name = "the Name",
  11. Description = "the Description"
  12. });
  13. dbCtx.SaveChanges();
  14. }
  15. }
  16.  
  17. modelBuilder.Entity<Product>().HasData(
  18. new Product
  19. {
  20. Id = 1,
  21. Name = "the Name",
  22. Description = "the Description"
  23. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement