目前我正在試圖給帳戶模型類中添加一個額外的模型,像這樣加公司的模式,以賬戶類
public class RegisterViewModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public int companyID { get; set; }
public virtual CompanyDetails company { get; set; }
}
public class CompanyDetails
{
[Key]
public int companyID { get; set; }
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 1)]
[Display(Name = "Company Name")]
public string CompanyName { get; set; }
}
我什麼不知道的是如何創建一個DBSet有公司類,並會公司的ID欄出現在用戶表中?
您有一個名爲View Model的類型,但想要一個'DbSet':我想你可能會混淆Model和View Model。你是在EF還是在客戶端尋找這個? –
Richard
@Richard我在EF尋找這個。我創建項目時自動生成了RegisterViewModel。 – Johnathon64
再次想到我不認爲這是EF。我試圖實現的基本上是在用戶表中有一個外鍵,它將連接到公司表 – Johnathon64