I have two tables with composite primary keys:
public class Event
{
[Key]
[Column(Order = 1)]
public string ID1 { get; set; }
[Key]
[Column(Order = 2)]
public int ID2 { get; set; }
public DateTime EventDate { get; set; }
public string DocID1 { get; set; }
public int DocID2 { get; set; }
}
public class EventDocument
{
[Key]
[Column(Order = 1)]
public string ID1 { get; set; }
[Key]
[Column(Order = 2)]
public int ID2 { get; set; }
public string Name { get; set; }
public string SurName { get; set; }
public string Number { get; set; }
public virtual ICollection<Event> Events { get; set; }
}
I need to create a composite foreign key on Event
table to EventDocument
table
I've tried to create FK like this
class Event:
[ForeignKey("DocID1")]
[Column(Order = 0)]
public string DocID1 { get; set; }
[ForeignKey("DocID2")]
[Column(Order = 1)]
public string DocID2 { get; set; }
But I get an error:
The property 'DocID1' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection where T is a valid entity type."}
I don't understand anymore what I am doing wrong