【发布时间】:2015-12-22 17:02:41
【问题描述】:
一开始我已经尝试过,如下所示,但仍然没有结果:
- Defining two foreign keys as primary key in Entity Framework
- Entity Framework Two foreign keys as primary key
这是我的实体:
public class Passage
{
[Key, ForeignKey("FromID")]
public Localization From { get; set; }
public int ToID { get; set; }
[Key, ForeignKey("ToID")]
public Localization To { get; set; }
[Required]
public string HourForm { get; set; }
[Required]
public string HourTo { get; set; }
[Required]
public int Seats { get; set; }
[Required]
public char Weekend { get; set; }
public int? AdditinalTime { get; set; }
public int FromID { get; set; }
}
我正在尝试基于两个外键创建主键。有错误
EntityType 'Passage' 没有定义键。定义此 EntityType 的键。
我做错了什么?
【问题讨论】:
标签: sql-server entity-framework ef-code-first