【发布时间】:2011-12-22 12:42:14
【问题描述】:
我有三个表,它们之间有以下关系:
Account {
public int Id;
}
Job {
public int Id;
public int AccountId;
}
Practice {
public int Id;
public int AccountId;
public string Name;
}
我希望能够通过 Job 对象访问 Practice 对象,如下所示:
Job.Account.Practice.Name
数据库结构是预先存在的,因此无法更改它。我想让 EF 提供对这种关系的访问,我相信它可以。我确实通过将 ICollection 导航属性放在 Account 类的 Practice 上并使用 ForeignKey 注释 Practice 类上的 Account 导航属性来使其工作,但必须有一种方法可以在不使用集合的情况下做到这一点。
那么,问题是,我应该尝试使用哪些数据注释属性来获得所需的结果?
【问题讨论】:
标签: entity-framework-4 data-annotations code-first