Ich habe Tabelle, wo ich zwei selbst fremde Schlüssel als Next und Previous haben möchte.Selbstreferenz in Entity Framework
Hier wie es aussehen:
public class BoxDefinition : ISiblingable
{
public int BoxDefinitionId { get; set; }
public string Name { get; set; }
public byte[] Photo { get; set; }
public bool Active { get; set; }
[ForeignKey("Next")]
public int? NextId { get; set; }
[ForeignKey("Previous")]
public int? PreviousId { get; set; }
public BoxDefinition Next { get; set; }
public BoxDefinition Previous { get; set; }
//public virtual ICollection<BoxDefinition> NextSiblings { get; set; }
//public virtual ICollection<BoxDefinition> PreviousSiblings { get; set; }
public static BoxDefinition GetById(int id, IContext context)
{
return context.BoxDefinitions.SingleOrDefault(b => b.BoxDefinitionId == id);
}
}
Als ich Kommentar- diese beiden Sammlungen alles funktioniert, aber in dieser Entität ich viele brauchen, weil jede Instanz nur ONE nächsten und vorherigen oder null hat. Hier
ist der Fehler:
BoxDefinition_Previous_Target: : Multiplicity is not valid in Role 'BoxDefinition_Previous_Target' in relationship 'BoxDefinition_Previous'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
Entity Framework vielleicht denken, dass es sollte Sammlung sein, weil es viele Referenzen sein könnte, aber ich weiß es nicht.
Irgendwelche Ideen?