How do I specify the maximum column length of a field using entity framework code first

alternatively, you can manually do it on Fluent API

use HasMaxLength(450)

  • Configuring Properties and Types with the Fluent API
    • EF 6
    • EF Core

or if you want Data Annotation, use MaxLength and MinLength attributes

public class EntityRegister
{
    public int Id { get; set; }
    [MaxLength(450)]
    public string Name { get; set; }
}
  • Code First Data Annotations

Leave a Comment