Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Extensions.DependencyInjection;
- using StackStore.Data;
- using System.Collections.Generic;
- using System.Linq;
- namespace StackStore.Models
- {
- // http://stackoverflow.25lm.com/questions/34536021/seed-initial-data-in-entity-framework-7-rc-1-and-asp-net-mvc-6
- public static class DataSeeder // EntityFramework 7.0 DataSeeder
- {
- public static void SeedData(this IServiceScopeFactory scopeFactory)
- {
- using (var serviceScope = scopeFactory.CreateScope())
- {
- var context = serviceScope.ServiceProvider.GetService<ApplicationDbContext>();
- if (!context.ApplicationUsers.Any())
- {
- var Users = new List<ApplicationUser>
- {
- new ApplicationUser
- {
- }
- };
- context.AddRange(Users);
- context.SaveChanges();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement