Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using Microsoft.Extensions.DependencyInjection;
  2. using StackStore.Data;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace StackStore.Models
  7. {
  8. // http://stackoverflow.25lm.com/questions/34536021/seed-initial-data-in-entity-framework-7-rc-1-and-asp-net-mvc-6
  9. public static class DataSeeder // EntityFramework 7.0 DataSeeder
  10. {
  11. public static void SeedData(this IServiceScopeFactory scopeFactory)
  12. {
  13. using (var serviceScope = scopeFactory.CreateScope())
  14. {
  15. var context = serviceScope.ServiceProvider.GetService<ApplicationDbContext>();
  16. if (!context.ApplicationUsers.Any())
  17. {
  18. var Users = new List<ApplicationUser>
  19. {
  20. new ApplicationUser
  21. {
  22.  
  23. }
  24. };
  25. context.AddRange(Users);
  26. context.SaveChanges();
  27. }
  28. }
  29.  
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement