5身分与另一对象

5身分与另一对象

本文介绍了扩展ASP.NET MVC 5身分与另一对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用流利的API中,我无法找到关于与另一个对象扩展标识模型的资源。

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

在这里,我有我的对象调用ApplicationUser:

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?
}

我有一些局限性,因为我试图通过使用PCL轮廓78重用我的模型,因为这个,我不能包含EF库,并有能力使用流利的API。

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.

有没有更简单的方法来做到这一点,或这是正确的做法?有关如何扩展或连接ApplicationUser进一步的目的将是真正的AP preciated的任何信息。

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.

推荐答案

在你的DbContext类覆盖OnModelCreating(DbModelBuilder模型构建器)

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

这篇关于扩展ASP.NET MVC 5身分与另一对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:27