【发布时间】:2011-07-18 03:31:49
【问题描述】:
我正在尝试使用 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 吗?我错过了什么吗?
谢谢!
【问题讨论】:
标签: asp.net-mvc-3 entity-framework-4 entity-relationship ef-code-first entity-framework-4.1