I have a code-first EF model based on 4.3.1.
In this model there is a ZeroOrOne relation between two tables: Session and Event.
An Event can have exactly one Session, but there are also Events (like general startup Events) which have no Session. Many Events can share the sane Session.
In my Entities class, I can see that this FK-relationship is mapped:
[assembly: EdmRelationshipAttribute("MyModel", "fk_event_session", "Session", System.Data.Metadata.Edm.RelationshipMultiplicity.ZeroOrOne, typeof(Data.Session), "Event", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(Data.Event), true)]
However, when I try to add a new Event with SessionID null, my application throws a Foreign Key exception on this relation. Is this an EF bug or are there some other things I should check?
Thanks in advance.
I figured out what the problem was, there was something wrong in the Model which caused the properties to not be generated. Somehow the “Referential Constraint” was empty so I deleted and readded the association and now it works.