使用另一个对象扩展ASP.NET MVC 5标识

我目前正在使用Fluent API,在其中找不到有关使用其他对象扩展Identity模型的许多资源。

在这里,我有一个名为ApplicationUser的对象:

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

我想将它映射到我当前的Staff对象:

 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 Jobs { get; set; } public virtual ICollection LineItems { get; set; } //Add ApplicationUser here? } 

我有一些限制,因为我试图通过使用PCL配置文件78来重用我的模型。因此,我不能包含EF库并且必须使用Fluent API。

有没有更简单的方法来做这个或这是正确的方法? 有关如何“扩展”或“链接”ApplicationUser对象的任何信息都将非常受欢迎。

在你的DbContext类中重写OnModelCreating(DbModelBuilder modelBuilder)

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

我很抱歉我的英语很差,希望这对你很有帮助