Identity 3.0实体框架核心1.0外键

时间:2016-07-15 18:37:50

标签: entity-framework-core

我正在尝试连接CompanyApplicationUser : IdentityUser之间的一对多关系。在我的ApplicationUser课程中,我有:

 public class ApplicationUser : IdentityUser
 {
    [ForeignKey("CompanyId")]
    public int CompanyId { get; set; }
 }

public class Company
{
    [Key]
    public int CompanyId { get; set; }

    public string Name { get; set; }

    ...
 }

但我收到了System.ArgumentException:

Microsoft.EntityFrameworkCore.Infrastructure.IDbContextFactory 1[TContext]' violates the constraint of type 'TContext'

1 个答案:

答案 0 :(得分:0)

您可以像这样设置关系。

public class ApplicationUser : IdentityUser
 {

    public Company Company { get; set; }
 }