I have a class with a composite primary key that's used as a lookup table for 3 different tables. So, the primary key is a composite of the 3 corresponding foreign keys.
I want to use one of the keys in the composite key as a foreign key to another table.
here is the lookup table mapping
public MultiMap()
{
ToTable("multi");
HasKey(t => t.ParentId);
HasKey(t => t.AttributeId);
HasKey(t => t.ItemId);
Property(t => t.ParentId).HasColumnName("parent_id");
Property(t => t.AttributeId).HasColumnName("attribute_id");
Property(t => t.ItemId).HasColumnName("item_id");
}
I want to use ItemID as a foreign key to map to another table, but it's not working.
I'm trying to use this to map it
HasRequired(t => t.ListItem).WithMany().HasForeignKey(t => t.ItemId);
But it's not working.
I assume it's because it's trying to map the composite primary key to the foreign key. Which is just an int.
I'm getting the message of
Multiplicity is not valid in Role 'XXX' in relationship 'XXX'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be '1'.
How should I be doing the mapping?