I seem to be having trouble with database first multiplicity within the design. I am using EF v5.0
I have two db entities with the following (psuedo classes for example):
entity {
long Id; //PK
bool myProp;
}
entity_detail {
long entityID; //FK to entity.Id
string name;
datetime entered;
}
When I update the model from the database it correctly generates these classes in the .tt, however, it puts the entity_detail
into an ICollection<entity_detail>
in the entity
class.
This is due to the multiplicity, when I change the multiplicity from Many (*)
to Zero or One (0..1)
within the EDMX, it will error out and force me to use Many (*)
The issue with this scenario is that the entity_detail
should ONLY be generated if myProp
is set to false (to avoid redundant data in db)
Thus being a 0..1, any idea on how to set this up from the database perspective to get the EDMX to update it to 0..1 on the entity end and 1 on the entity_detail end?
Thanks in advance!
For anyone looking for the answer, the correct setup was to make the foreign key (
entityID
) column on theentity_detail
object also a primary key.This way it would be unique but only be required if it exists (
0..1
)Hope this helps!