Question

I'm using table per hierarchy inheritance within my enitity model and I have a parent table that contains relationships to other tables via foreign keys.

My parent table (Product) has a FK relationship to another table which in EF resolves to a Navigation Property. I can easily move that navigation property to my child table (Fragrance) and delete it from the parent which is great. However I also want to move the foreign key property (FragranceId) to the child but I can't work out how to do this because the FK relationship requires that my parent table has that property.

The diagram below illustrates how far I've got, basically what I'm trying to do is move the FragranceId into the Perfume entity.

Diagram

It seems like this should be possible but since Perfume is not a table it can't take on the database relationship and while that relationship exists between Fragrance and Property I can't remove FragranceId from Product.

Moving the FragranceId leads to an EF error 'there is no property with the name FragranceId defined in the type referred by Role Product.

The relationship between Fragrance and Perfume is 1 to 1.

Any help would be awesome. Thanks.

Was it helpful?

Solution

So it turns out the answer is pretty simple I just needed to delete the database foreign key relationship from my entity model and I could move the FragranceId to the perfume entity.

I then needed to manually remove all reference to the FK from the edmx file's XML to resolve error 3015 and finally re-map the FragranceId to fix error 3004.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top