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?
Best Answer
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
andOrderLine
entities:As you can see there is no
OrderId
in theOrderLine
entity and referential constraints of the relation are empty. Also mapping of the relation is specified.BUT you can't never remove
Id
fromCompanyType
. Ids (PKs) are mandatory. You can only change its accessibility in its properties.