【发布时间】:2011-05-11 09:27:33
【问题描述】:
我有这个代码:
class Country
{
public int CountryId { get; set; }
public string CountryName { get; set; }
}
class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public int ResidingInCountryId { get; set; }
public virtual Country ResidenceCountry { get; set; }
}
我应该在 OnModelCreating 上添加什么?所以我可以从 Employee 导航 Country 的 CountryName
【问题讨论】:
-
您是否使用 EF 4.1 代码优先?
-
是的,我首先使用带有代码的 EF 4.1。我更新了我的问题。我认为
virtual Country ResidenceCountry需要手动映射。ResidenceCountry属性的实际后备数据库字段是 ResidingInCountryId -
我已经更新了我的答案,希望对您有所帮助。我自己还在学习这些东西。