我正在尝试使用 EF 4.1 的 RC 版本创建一个快速的 ASP.NET MVC 3 应用程序。我有两个模型:
public class Race
{
public int RaceId { get; set; }
public string RaceName { get; set; }
public string RaceDescription { get; set; }
public DateTime? RaceDate { get; set; }
public decimal? Budget { get; set; }
public Guid? UserId { get; set; }
public int? AddressId { get; set; }
public virtual Address Address { get; set; }
}
和
public class Address
{
public int AddressId { get; set; }
public string Street { get; set; }
public string StreetCont { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
public virtual Race Race { get; set; }
}
尝试插入新 Race 时出现以下错误:
无法确定类型“rcommander.Models.Race”和“rcommander.Models.Address”之间关联的主体端。此关联的主体端必须使用关系流式 API 或数据注释显式配置。
它不应该自动将 RaceId 识别为 Races 表的主键,将 AddressId 识别为 Addresses 表的 FK 吗?我错过了什么吗?
谢谢!