13

Is it possible for Entity Framework 4.0 to have an association/navigation property based off of a foreign key to a non-primary key field (it has a unique constraint).

DavidRR
  • 18,291
  • 25
  • 109
  • 191
devlife
  • 15,275
  • 27
  • 77
  • 131
  • Possible duplicate of [Create association on non-primary key fields with Entity Framework 4.1 Fluent API](https://stackoverflow.com/questions/7019052/create-association-on-non-primary-key-fields-with-entity-framework-4-1-fluent-ap) – DavidRR Nov 01 '18 at 14:21
  • Voted to close as a duplicate though I believe that this question very nicely and concisely expresses the intent of the desired capability. Please note that an [answer](https://stackoverflow.com/a/53102674/1497596) I provided at the referenced question indicates that Microsoft implemented this capability in EF Core 1.0 (EF7), but has no plans to implement it in EF6. – DavidRR Nov 01 '18 at 14:25

1 Answers1

9

No because EF don't understand unique constraint yet and relations in EF must follow same rules as relations in database. Without unique principal relation cannot exist and the only way to get unique principal in EF is using primary key.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670