【发布时间】:2011-05-20 13:06:52
【问题描述】:
让我们用一个简单的例子:
public class Employee
{
public int EmployeeID { get; set; }
public ICollection<Pay> Pays { get; set; }
}
public class Pay
{
public Employee Employee { get; set; }
public int Year { get; set; }
public double Amount { get; set; }
}
有什么方法可以使用 fluent API 创建一个主键为 Employee_EmployeeID, Year 的 Pays 表(使用 EF4.1 列约定)?
我不想使用数据注释,但我还是尝试了这个:
public class Pay
{
[Key, Column(Order = 0)]
public Employee Employee { get; set; }
[Key, Column(Order = 1)]
public int Year { get; set; }
public double Amount { get; set; }
}
我得到的只是Year 上的主键和Employee_EmployeeID 上的外键。
【问题讨论】:
标签: entity-framework-4.1 fluent-interface