我使用与 MVC 4 身份验证方法相关的实体框架。我创建了一个自定义  UserProfile以包含其他一些表格。
用户资料
[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public int CompanyId { get; set; }
    [ForeignKey("CompanyId")]
    public virtual Company Company { get; set; }
}
公司
public class Company
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
}
现在WebSecurity.CreateUserAndAccount("MyUser", "MyPassword");向我抛出以下异常:
Cannot insert the value NULL into column 'CompanyId', table 'aspnet.web-67.dbo.UserProfile'; column does not allow nulls. INSERT fails. The statement has been terminated.
我可以删除 ForeignKey,但在此之后延迟加载似乎不再起作用。