There is no property with name 'restriction_class_id' defined in type referred by Role 'phones_extensions'

落爺英雄遲暮 提交于 2019-12-10 18:08:45

问题


I created a new Entity Framework model from a database. This database has a number of tables, the main table is phones_extensions. The phones_extensions table has columns which are FK's to the other tables - e.g. the restriction_class_id is an FK linking to the phones_restictions_class table where the PK is ID.

The EF4 model automatically generates associations for the tables. Great. Now when I run my application I see not only the numeric restriction_class_id but I also see the textual content pulled in by the association (e.g. phones_restriction_class.name).

But what if I don't want to keep all those extra columns? I right click and delete the restriction_class_id but now I get the error mentioned in the subject of this question.

Is there a way for me to remove the columns so I don't have to mess with them in my applicaiton but still have the associations display correctly?


回答1:


When you generate your model, un-check the option "Include foreign key columns in the model on the "Choose Your Database Objects" page of the wizard.




回答2:


I removed a column that related to a foreign table and had the same error message. I deleted every reference that I could find to the foreign key constraint, and still had the message. I updated the model once again, and the error went away.




回答3:


You can delete obsolete associations (foreign keys) from the Model diagram:

1- Track any Error 111 in the errors pane.

2- Double click the error and it will focus the view on the model diagram with a highlight on the invalid association.

3- Press "Del" on the keyboard.

4- Rebuild the project

I hope this will help some programmer before he gets fired from his job because of this problem ;)



来源:https://stackoverflow.com/questions/3007274/there-is-no-property-with-name-restriction-class-id-defined-in-type-referred-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!