I have problems with some logged entities from a read-only database. Among other, i read 4 tables, EntityOne, EntityTwo, EntityOneLogged and EntityTwoLogged.
EntityOne has a 3-part compositekey, KeyString1, KeyString2, KeyString3
EntityTwo has a 4-part compositekey, KeyString1, KeyString2, KeyString3, KeyString4
EntityOne has a one to many relationship with EntityTwo
this works and is mapped like this:
HasRequired(r => r.EntityOne).WithMany(m => m.EntityTwos).HasForeignKey(f => new { f.KeyString1, f.KeyString2, f.KeyString3 });
EntityOneLogged has a 4-part compositekey, KeyString1, KeyString2, KeyString3, ActionTime
EntityTwoLogged has a 5-part compositekey, KeyString1, KeyString2, KeyString3, KeyString4, ActionTime
EntityOneLogged has a many to many relationship with EntityTwo (not mappable)
The logged tables can contain removed rows from the normal table
The problem starts here, when i want to map 0..1 to many from EntityTwoLogged to EntityOne
HasOptional(r => r.EntityOne).WithMany(m => m.EntityTwoLogs).HasForeignKey(f => new { f.KeyString1, f.KeyString2, f.KeyString3 });
This fails validation with the following error:
One or more validation errors were detected during model generation: EntityTwoLogged_EntityOne: : Multiplicity conflicts with the referential constraint in Role 'EntityTwoLogged_EntityOne_Target' in relationship 'EntityTwoLogged_EntityOne'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.
Which I interpret as a fault in EF as all combination of composite keys have to exist in all related tables? Or do i miss something?