【发布时间】:2009-12-18 07:56:38
【问题描述】:
我正在使用 EF v1。我有以下表格:
CREATE TABLE category (
category_id int ,
category_name varchar(100) not null,
CONSTRAINT PRIMARY KEY (category_id)
)
CREATE TABLE categoryDetails (
detail_id int,
category_desc varchar(100) not null,
category_id int NOT NULL,
CONSTRAINT PRIMARY KEY (detail_id),
CONSTRAINT FOREIGN KEY (category_id) REFERENCES category(category_id)
)
一个'category'可以有0..1个'categoryDetails'。
在从上述数据库生成的 EF 模型中,EF 将 SSDL 和 CSDL 中的关系建模为 *。 使用设计器 CSDL,我可以将关系/关联从 * 更改为 0..1。但是在检查 SSDL 时,它仍然是 *. 在 SSDL 中将其更改为 0..1 时,出现错误:
"Multiplicity is not valid in Role R111 in relationship RL111. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *."
请告诉如何更改 SSDL ?
在这种情况下(CSDL 中的 0..1 和 SSDL 中的 *)部分类是根据 0..1 关系为代码创建的(即每个类中的单个引用属性,包含另一个类的类型 -不涉及收集)。 在运行代码时,它运行没有错误。 这是否正确(SSDL 和 CSDL 中的多重性不同)?
对于表结构不能改变的情况,有什么办法可以得到0..1关联?
谢谢。
【问题讨论】:
标签: entity-framework