I am using EF6 (Code First) in a project.
Having a class below:
public class State
{
    public int ID { get; set; }
    [Required]
    [StringLength(10)]
    public string Code { get; set; }
    [Required]
    [StringLength(50)]
    public string Name { get; set; }
    [Required]
    public Country Country { get; set; }
}
I expect to have Codeboth nvarchar(10)in the database, but I get nvarchar(3). I see the correct length for the column Name, but I can not understand why it was Codecreated incorrectly.
Edit: I have a Country class as shown below:
public class Country
{
    [Key]
    [StringLength(3)]
    public string Code { get; set; }
    [Required]
    [StringLength(50)]
    public string Name { get; set; }
}
I think EF believes that the Code in State class is a Code in Country class, as there is an association between them.
Now the question is, how should I tell EF that the Code in State class is not a Foreign Key to Country class?
source
share