Да, вы можете определить составной внешний ключ с аннотациями данных:
public class Table2
{
[ForeignKey("Table1"), Column(Order = 1)]
public virtual int Key1 {get; set;}
[ForeignKey("Table1"), Column(Order = 2)]
public virtual int Key2 {get; set;}
[InverseProperty("Tables2")]
public virtual Table1 Table1 {get; set;}
//more properties here...
}
Или альтернативно:
public class Table2
{
public virtual int Key1 {get; set;}
public virtual int Key2 {get; set;}
[InverseProperty("Tables2")]
[ForeignKey("Key1, Key2")]
public virtual Table1 Table1 {get; set;}
//more properties here...
}
Но реальная проблема в том, что у вашего Table2
нет первичного ключа, который требуется Entity Framework. Я не думаю, что есть какой-то обходной путь для решения этой проблемы, кроме добавления первичного ключа в таблицу.