Reputation: 24063
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'.
How can I remove those id's from the POCOs without getting the exception?
Upvotes: 6
Views: 6148
Reputation: 364279
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.
Here is the screen shot from one of my testing application with one-to-many relation between Order
and OrderLine
entities:
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.
Upvotes: 8
Reputation: 2556
When you imported in your Model from your DB you are asked if you want to:
"Include Foreign key columns in the model" you need to switch this off.
Upvotes: 4