我有一个entityframewrok问题,它将两个表之间的1:0..1关系序列化为一个集合。EntityFramework:1:0..1关系反序列化为集合
我有我的数据库2个表:
CREATE TABLE `revisiones` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
---Irrelevant columns here---
PRIMARY KEY (`Id`),
---Irrelevant constraint and foreign keys here---
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `ficha_deposito` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`IdRevision` int(11) NOT NULL,
---Irrelevant Columns Here---
PRIMARY KEY (`Id`),
UNIQUE KEY `IdRevision_UNIQUE` (`IdRevision`),
CONSTRAINT `fk_ficdep_rev` FOREIGN KEY (`IdRevision`) REFERENCES `revisiones` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
---Irrelevant constraints here---
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
正如你可以看到一个版本可能与为无或1个ficha_deposito,由于独特的限制。
但是在EDMX文件,关系序列化为一个集合:
如果我尝试手动更改它(我宁愿没有这样做,因为如果我必须重新生成模型,我将不得不再次手动设置的值),然后我得到一个异常:
Running transformation: Multiplicity is not valid in Role 'ficha_deposito' in relationship 'fk_ficdep_rev'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.
为什么我不能改变关系的多重性?revision.ficha_deposito
应该为空或简单的对象。
这是因为EF6不支持'一对一'FK关联。看看[一对一外键关联](http://weblogs.asp.net/manavi/associations-in-ef-4-1-code-first-part-5-one-to-one - 外键密钥关联)和[共享主键关联](http://weblogs.asp.net/manavi/associations-in-ef-4-1-code-first-part-3-shared-primary-key -associations) –