Delete a foreign key property throws an exception

I do not want to use the foreign key association in CompanyType (the member that will store the foreign key identifier), but prefers to use the navigation property. Therefore, I deleted CompanyTypeId.

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

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

enter image description here

How to remove this identifier from POCOs without getting an exception?

+6
source share
2 answers

This is the difference between a Foreign Key Association and an independent association . Both associations use navigation properties, but only foreign key associations use the FK property. You can either delete them around the world, as @Robbie mentioned, or change the type manually for the selected relationship.

  • Choose a relationship in entity design
  • Remove link restrictions in properties
  • Go to the mapping window and match the relation

Here is a screenshot from one of my test applications with a one-to-many relationship between Order and OrderLine :

enter image description here

As you can see, there is no OrderId in the OrderLine object, and the reference constraints of the relation are empty. Relationship mapping is also indicated.

BUT you cannot remove Id from CompanyType . Identifiers (PCs) are required. You can change its availability only in your properties.

+8
source

When you imported into your model from your database, you will be asked if you want to:

β€œInclude foreign key columns in the model” you need to disable this.

enter image description here

+4
source

Source: https://habr.com/ru/post/886428/


All Articles