I have some entities that can be associated with each other. A simple pair of classes to do this would ideally look like:
public class linkableEntity
{
public int Id { get; set;}
public virtual ICollection<Link> Links { get; set; }
}
public class Link
{
public int Id { get; set; }
public int SomeProperty { get; set; }
public int entity1Id { get; set; }
public virtual LinkableEntity entity1 { get; set;}
public int entity2Id { get; set; }
public virtual LinkableEntity entity2 { get; set;}
}
With tables something like:
Table linkableEntity
Column Id
Table link
Column entityId1 - foreign key to linkableEntity.Id
Column entityId2 - foreign key to linkableEntity.Id
Column someProperty
Having tried this out, and looking at this question: Entity Framework Code First - two Foreign Keys from same table I don't think that what I want to do was possible in EF4, has anything changed in EF6 that would make this possible? (I haven't found any more recent questions addressing this subject)
If not, is there a better way of representing this than changing linkableEntity to something like:
public class linkableEntity
{
public int Id { get; set;}
public virtual ICollection<Link> LinksWhereFirst { get; set; }
public virtual ICollection<Link> LinksWhereSecond { get; set; }
}
and then dealing with the mess?