我正在尝试实现实体框架的代码优先方法。我有四个实体UserInfo
、Client
和。我希望关系为:Admin
Account
- 每个
Client
都有一个UserInfo
- 每个
Admin
都有一个`UserInfo - 每个
Account
都与一个 User(UserInfo
)链接
假设这些东西我写了 POCO 模型。有了我想要的关系,它是否正确?我错过了什么吗?
public class UserInfo
{
public int UserInfoID { get; set; }
public Name Name { get; set; }
public Address Address { get; set; }
public Contact Contact { get; set; }
}
public class Admin
{
public int AdminID { get; set; }
public int UserInfoID { get; set; }
[ForeignKey("UserInfoID")]
public virtual UserInfo UserInfo { get; set; }
}
public class Client
{
public int ClientID { get; set; }
public CompanyDetails CompanyDetails { get; set; }
public int UserInfoID { get; set; }
[ForeignKey("UserInfoID")]
public virtual UserInfo UserInfo { get; set; }
}
public class Account
{
public int AccountID { get; set; }
[Required, Column("Balance"), Display(Name = "Account Balance")]
public double Balance { get; set; }
public int UserInfoID { get; set; }
[ForeignKey("UserInfoID")]
public virtual UserInfo UserInfo { get; set; }
}