I have the following table structure that Entity Framework is correctly returning as a one-to-many:
Patient
{
PatientId PK
}
Death
{
DeathId PK
PatientId FK
}
Unfortunately this DB design is wrong as you can only have one Death
per Patient
. The design should of been like this instead:
Death
{
PatientId PK
}
However, this is a production system and the DB is not able to be changed. I am writing a new ASP.Net MVC front-end, so I'm rewriting the DAL layer using Entity Framework.
When I call Patient.Death
, I get a collection of Death
. I only want it to return me a single or null Death
(as the Patient
may not yet be dead).
So, I went wading into the Model and tried to change the End2 Multiplicity of the assocation to: 0..1 (Zero or One of Death)
, but when I build the project I get the error:
Multiplicity is not valid in Role 'Death' in relationship 'RefDeath23'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.
Can anyone tell me how, if possible, I can force this to be a zero or one association?