Seeding Identity 2.0 database

前端 未结 5 1568
走了就别回头了
走了就别回头了 2021-02-06 01:00

I have an ASP.NET MVC 5 project (razor engine) which has Identity 2.0 with Individual User Accounts. I am using Visual Studio Professional 2013

I have not found any clea

5条回答
  •  情歌与酒
    2021-02-06 01:42

    To complete this question.. As Corneliu Serediuc said all you need to do is simply try to connect to database during application startup, for example, like this (IdentityModel.cs):

    public class ApplicationDbContext : IdentityDbContext
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
            Database.SetInitializer(new ApplicationDbInitializer());
        }
    
    
        public static ApplicationDbContext Create()
        {
            var ctx = new ApplicationDbContext();
            var runSeed = ctx.Roles.AnyAsync();
    
            return ctx;
        }
    

    } By the way, Corneliu thank you for your code examples, they help me a lot.

提交回复
热议问题