0

I'm Using EF 4.1 Model First approach

Is it possible to have a foreign key relationship and a Navigation property at the same time for the same type.

For ex I have a Job entity and a field called PaymentType_ID with a foreign key relationship to a PaymentType entity. When I do an insert it works fine.

Then I add a Navigation property using the same association that is used for the FK, when I try insert I get the following error "Invalid column name 'PaymentType_PaymentTypeID'."

It seems EF is for some reason adding another column by itself even though a FK already exists.

Is this possible or what am I doing something wrong

Eugene Niemand
  • 721
  • 6
  • 28

2 Answers2

0

Yes it is possible but your property doesn't follow default naming convention so you must manually pair the FK with navigation property for example through data annotations:

[ForeignKey("PaymentType_ID")] // Name of FK property
public virtual PaymentType PaymentType { get; set; }
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
0

Yes it's possible You should clear navigation property & relationship see : https://msdn.microsoft.com/en-us/data/jj713564

Yahya Alshaar
  • 163
  • 1
  • 5