简体   繁体   English

实体框架协会错误一对多

[英]Entity Framework Association Error One to Many

Can anyone tell my why I am getting this error? 任何人都可以告诉我为什么会收到此错误? I have tried adding constraints but it causing tons of other errors and I cant figure it out. 我试过添加约束,但它导致了大量的其他错误,我无法弄明白。 It all looks ok to me :\\ 这对我来说都很好看:\\

This is the error i get 这是我得到的错误

Error   1   Error 3003: Problem in mapping fragments starting at line 265:Given the cardinality of Association End Member Contact, it should be mapped to key columns of the table tbl_Contact_Relationship. Either fix the mapping or change the multiplicity of this end.

在此输入图像描述

Thanks in advance. 提前致谢。

The issue here is that you're thinking "1 to Many" but in reality it's "0 or 1 to Many". 这里的问题是你在想“从1到多”,但实际上它是“0或1到很多”。

You can either modify this in the .edmx diagram designer or if you setup the foreign key in your database correctly (make sure you save the table after you exit the dialog window) and 'Update Model from Database' you'll get the mapping corrected automagically. 您可以在.edmx图设计器中修改它,或者如果在数据库中正确设置外键(确保在退出对话框窗口后保存表)和“从数据库更新模型”,您将得到更正的映射自动的。

Fixed this, have no idea how. 修正了这个,不知道怎么做。 Removed the tbl_Contact_Relationship and added it back in and it is working now. 删除了tbl_Contact_Relationship并将其重新添加,现在正在运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM