Extending ASP.NET MVC 5 Identity with another object

陌路散爱 提交于 2019-12-06 15:45:26

问题


I'm currently using Fluent API in which I cannot find many resources regarding extending the Identity model with another object.

Here I have my object called ApplicationUser:

public class ApplicationUser : IdentityUser
{
    public virtual Staff Staff { get; set; }

    public int StaffId { get; set; }
}

In which I'd like to map it to my current Staff object:

public class Staff
{
    public int StaffId { get; set; }

    public string DisplayName { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public UserTitleEnum Title { get; set; }

    public string Phone { get; set; }

    public string Email { get; set; }

    public virtual ICollection<Job> Jobs { get; set; }

    public virtual ICollection<LineItem> LineItems { get; set; }

    //Add ApplicationUser here?
}

I have a few limitations as I'm trying to reuse my models by using a PCL profile 78. Because of this, I cannot include EF libraries and have to use Fluent API.

Is there a simpler way to do this or is this the right approach? Any information about how to "extend" or "link" the ApplicationUser object further would be really appreciated.


回答1:


in your DbContext class override OnModelCreating(DbModelBuilder modelBuilder)

modelBuilder.Entity<Staff>().ToTable("Staff");
modelBuilder.Entity<ApplicationUser>().HasRequired(x => x.Staff);

i am sorry for my poor english,hope this helpful



来源:https://stackoverflow.com/questions/20795892/extending-asp-net-mvc-5-identity-with-another-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!