Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 572
Dave Mackey Avatar asked Jun 09 '10 15:06

Dave Mackey


3 Answers

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.

like image 60
Craig Stuntz Avatar answered Nov 18 '22 11:11

Craig Stuntz


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.

like image 4
Glenn Gordon Avatar answered Nov 18 '22 12:11

Glenn Gordon


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 ;)

like image 1
Shadi Namrouti Avatar answered Nov 18 '22 12:11

Shadi Namrouti