Entity Framework Code First - foreign key for non-primary key field

I have two tables that look like this:

dbo.ReviewType
    ReviewTypeId INT PRIMARY KEY
    ShortName CHAR(1) - Unique Index
    Description

dbo.Review
   ReviewId INT PRIMARY KEY
   ReviewType_ShortName CHAR(1) - FK to ReviewType
   ...

There is always ReviewType in a review.
Review Type can be associated with many reviews.

I'm having trouble displaying this in the Entity Framework using the Code First Fluent API. I don't seem to like it when I use a foreign key that does not map to the Primary key. I use a foreign key for a unique constraint / index instead of the main key.

How can I correctly display this in Entity Framework using C #?

I should note that the way I am doing this right now gives me this error:

System.Data.Edm.EdmAssociationConstraint:: , . "ReviewTypeCode" " " Id " " ReviewType " " ReviewType_Reviews ".

+5
1

EF .

+4

All Articles