问题
I'm trying to develop an application as Model-First with EF. I tried everything to accomplish a table-splitting pattern and a 1:1 relationship but looks like EF just doesn't let me.
Assuming I do use Model-First - is there a way to put a 1:1 relationship without messing with the generated files and EF giving that annoying:
Multiplicity is not valid in Role 'Blablalah' in relationship 'Blabalbala'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.
I already tried to set my FK's as Primary Keys on destination tables but still doesn't help.
回答1:
1:1 relationship is generally defined by having foreign key in the first table and then having it cascade on delete, in database design.
IE: Users table and UserProperties table. Users table would have a UserPropertiesId as the foreign key and UserProperties would essentially treat Users as many Users to one UserProperties. That's just how things are, and if you only select by Users table it isn't an issue.
来源:https://stackoverflow.com/questions/14016035/11-relationship-problems-with-ef-model-first