Code First Foreign Key

52 Views Asked by At

I am new to entity framework. I have following models.

public partial class PropertyDetail
{
    public int PropertyID { get; set; }
    public string PropertyName { get; set; }
    public virtual PropertyAddress PropertyAddress { get; set; }  
    public string AnalyticsView { get; set; }
    public string MoreInformationLink { get; set; }

}

public class PropertyAddress
{
    public string PropertyName { get; set; }
    public string StreetAddress { get; set; }
    public string PostalCode { get; set; }
    public virtual PropertyDetail PropertyDetail { get; set; }
}

I want PropertyID from PropertyDetail to be primary key and PropertyName to be Foreign key in PropertyAddress table.

Thank for help.

1

There are 1 best solutions below

0
On

with EF6 you can't: the FK must be of the same type as the PK. I heard about that in EF7 but not for sure.