I need to save a string with a length larger than 2000 characters, but the Entity Framework validation "hangs" the string size in 2000 and returns me error message:
The Value field must be a string or array type with maximum length of '2000'.
In the database the field is VARCHAR (8000) and in the entity is defined MaxLength of 8000
Model
public class TermoUso : BaseEntity
{
public Guid TermoUsoKeyId { get; set; }
public virtual TermoUsoKey TermoUsoKey { get; set; }
[Required]
[MaxLength(8000)]
public string Texto { get; set; }
}
DataContext
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
modelBuilder.Properties<string>()
.Configure(c => c.HasColumnType("varchar"));
modelBuilder.Properties<string>()
.Configure(c => c.HasMaxLength(8000));
modelBuilder.Properties<DateTime>()
.Configure(c => c.HasColumnType("datetime2"));
}