You are getting an error because HeaderBackgroundColorId
is a non-nullable int
, so it cannot be optional.
All you need to do to achieve what you're looking for is to turn the foreign key into a nullable int
...
public int? HeaderBackgroundColorID { get; set; }
Because you named the foreign key to match the navigation property (HeadBackgroundColorId
and HeaderBackgroundColor
) which follows Code First conventions, you do not need to create any explicit mappings. Simply making the above change will make the relationship optional.