目前我正在试图给帐户模型类中添加一个额外的模型,像这样加公司的模式,以账户类
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