Search code examples
c#entity-frameworkentity-framework-4linq-to-entitiesnavigation-properties

Add Navigation Property Manually to Entity Framework


I need to add a navigation property between two Entities TableA and TableB

TableA

ID : Primary Key 

Code: String (Allows Null)

TableB

BID:  Primary Key

Code: String (Allows Null)

Now I want to add a navigation property to these Entities which are related by the code which is not a foreign key. Can anyone tell me how this is possible


Solution

  • It is not possible because code is not PK in any of your tables. Navigation properties follows same rules as database relations - in principal table you must use PK and in dependent you specify FK. Databases also offers selecting unique key in principal table but EF doesn't support unique keys yet.