我在MVC 3应用程序中使用Entity framework 4.1。我有一个实体,我有主键由两列(复合键)组成。并且这在另一个实体中用作外键。但部分关键需要在多个导航属性中使用。我如何创建关系?我没有运气就试过以下内容,因为您似乎无法在外键注释中指定多个导航属性:
public class Employee
{
[Key, Column(Order = 0), MaxLength(40)]
public string Id { get; set; }
[Key, Column(Order = 1)]
public int Company { get; set; }
[ForeignKey("CompanyId")]
public Company Company { get; set; }
}
public class Event
{
[Key, Column(Order = 0), MaxLength(40)]
public string EventReference { get; set; }
[Key, ForeignKey("AssignedEmployee, Organiser"), Column(Order = 1)]
public int CompanyId { get; set; }
public Employee AssignedEmployee { get; set; }
[ForeignKey("AssignedEmployee"), Column(Order = 0)]
public string EmployeeId { get; set; }
[ForeignKey("CompanyId")]
public Company Company { get; set; }
public Person Organiser { get; set; }
[ForeignKey("Organiser"), Column(Order = 0)]
public string OrganiserId { get; set; }
}
如果使用数据注释无法做到这一点,任何人都可以了解如何在代码中进行操作吗?