Entity framework foreign key instances

281 Views Asked by At

I have a table with two foreign key fields point to colour table.

BookCover -> ForegroundColour and

BookCover -> BackgroundColour

When I do Reverse Engineer Code First, it generates Colour and Colour1 in the BookCover class.

public virtual Colour Colour { get; set; }
public virtual Colour Colour1 { get; set; }

I have set the foreign name to be ForegroundColour and BackgroundColour. Is there a easy way let Entity frame work generate the ForegroundColour and BackgroundColour instead of Colour and Colour1?

2

There are 2 best solutions below

0
On

You can change the association names in the EF model designer. Once they have been changed, the framework will remember the new names, even if you update the model at a later time.

0
On

I have had a similar issue but I believe the answer to the question is you simply have to rename the Navagation property to what you want. The Entity Framwork designer will always keep you changes to the property names on the Conceptual side of things.