【发布时间】:2014-05-11 17:28:06
【问题描述】:
如何去除多余的 ID?
我有一个用户配置文件模型 - 一个用户配置文件有一个连接模型列表。连接模型有一个用户配置文件(拥有该连接的用户配置文件)和一个用户配置文件2(用户配置文件连接到的另一个用户配置文件)。 在我的数据库连接表中,我得到以下列:
|身份证 |确认 |连接类型 | UserProfile_UserId | UserProfile2_UserId | UserProfile_UserId1 |
此处 UserProfile_UserId 将始终与 UserProfile_UserId1 相同。我真的很想摆脱那个额外的 ID 列。
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public virtual ICollection<Connection> Connections { get; set; }
}
public class Connection
{
[Key]
public int Id { get; set; }
public bool Confirmed { get; set; }
public byte ConnectionType { get; set; }
public virtual UserProfile UserProfile { get; set; }
public virtual UserProfile UserProfile2 { get; set; }
}
任何帮助将不胜感激。
【问题讨论】:
标签: entity-framework ef-code-first foreign-keys