0

我有一个 WCF 数据服务 (5.5) 位于 EF (5.0) 模型上,当我查询 $metadata 时出现以下错误:

“发现一个 IEdmModel 实例验证失败。报以下错误:InvalidMultiplicityOfDependentEnd : 依赖端'QuestionsetMember'的多重性无效。因为依赖属性不代表依赖端键,依赖的多重性结尾必须是'*'。”

QuestionsetMember 有一个由2 列组成的复合主键,每列都与另一个表的主键挂钩,即从键的每一列到两个表的主键都存在一个外键。

我已经搜索但找不到关于“InvalidMultiplicityOfDependentEnd”的任何信息。还尝试摆弄 EDMX 中的关系,但更改 End Multiplicity 会导致错误,导致模型无法编译。

任何想法如何解决这个问题(希望不改变我的架构)?

4

1 回答 1

0

This seems to be a very rare error. I did not find anywhere else an explanation of that error. So i did find for me a solution after inspecting every single constraint and every column in both tables. To my great surprise the order of the primary key columns seems to be relevant.

For explanation: I do the database-design within the sql server management studion, and update my model with the entity framework designer.

First Table:

CREATE TABLE Table1
(
Column1 int NOT NULL,
Column2 int NOT NULL,
PRIMARY KEY (Column1,Column2)
)

Second Table:

CREATE TABLE Table2
(
Column1 int NOT NULL,
Column2 int NOT NULL,
PRIMARY KEY (Column1,Column2)
FOREIGN KEY (Column1,Column2) REFERENCES Table1(Column1,Column2)
)

This would work. But it do not work, if you would define the columns of the primary key in the second table in another order:

CREATE TABLE Table2
(
-- Changed order in definition:
Column1 int NOT NULL,
Column2 int NOT NULL,
-- Changed order in PK group:
PRIMARY KEY (Column2,Column1)
-- Leave the FK definition untouched:
FOREIGN KEY (Column1,Column2) REFERENCES Table1(Column1,Column2)
)

I think the order of the column definition has impact on the generated model. And this order could maybe have an impact in the model validation within the IEdmModel class. Who knows...

于 2013-12-06T17:19:37.157 回答