MVC 4 인증 방법과 관련하여 Entity Framework를 사용합니다. 다른 테이블을 포함하기 위해 사용자 정의 UserProfile
을 생성했습니다.MVC 4 UserProfile 외래 키/널 (null) 오류를 허용하지 않습니다.
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를 제거 할 수 있지만 이후에는 지연로드가 더 이상 작동하지 않는 것 같습니다.
지불이 회사가 만드는 befor을 당신은 회사 ID 값을 추가해야합니다? 나는 이것을 이해할 수 없다. –
Lool 실수입니다. –