Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove foreign key property cause an exception

I don't want to use foreign key association to CompanyType (member that will hold the foreign key id) but prefer to use navigation property. So I removed the CompanyTypeId.

I get this exception that relates the relationship between entity Company and CompanyType:

Error 5: The element 'Principal' in namespace 'http://schemas.microsoft.com/ado/2008/09/edm' has incomplete content. List of possible elements expected: 'PropertyRef' in namespace 'http://schemas.microsoft.com/ado/2008/09/edm'.

enter image description here

How can I remove those id's from the POCOs without getting the exception?

like image 1000
Naor Avatar asked Apr 21 '11 22:04

Naor


1 Answers

This is the difference between Foreign key association and Independent association. Both associations use navigation properties but only Foreign key association uses FK property as well. You can either remove them globally as @Robbie mentioned or you can change the type manually for selected relation.

  • Select the relation in entity framework designer
  • In properties remove Referential constraints
  • Go to Mapping window and map the relation

Here is the screen shot from one of my testing application with one-to-many relation between Order and OrderLine entities:

enter image description here

As you can see there is no OrderId in the OrderLine entity and referential constraints of the relation are empty. Also mapping of the relation is specified.

BUT you can't never remove Id from CompanyType. Ids (PKs) are mandatory. You can only change its accessibility in its properties.

like image 93
Ladislav Mrnka Avatar answered Nov 12 '22 23:11

Ladislav Mrnka