Farther extending ApplicationUser class in ASP.NET MVC5 Identity system

后端 未结 2 1326
谎友^
谎友^ 2021-01-12 04:58

I\'m creating a simple application for university where a student can make some type of request which is then processed by an employee of particular speciality.

I wo

相关标签:
2条回答
  • @Dragonheart: I tried this repro and it would work fine if you remove the DBSet declarations in you context class. The IdentityDbContext would handle you TPH pattern and add a Discriminator column in the table to differentiate the child classes.

    0 讨论(0)
  • 2021-01-12 05:36

    As ApplicationUser is inherited from IdentityUser, remove it from your DbContext class. On the other hand, there is no need to create an abstract class (you can create if you prevent from creating a user except from Student or Employee classes. For more information you might have a look at Table-per-Hierarchy.

    For Register part, try something like that:

    Student user = new Student
    {
        UserName = model.UserName,
        FirstName = model.FirstName,
        LastName = model.LastName,
        Email = model.Email
    };
    var result = UserManager.Create(user, model.Password);
    

    Hope this helps...

    0 讨论(0)
提交回复
热议问题