Entity Framework: Data Model with column with the largest possible number of characters

3

I'm creating tables with Entity Framework , and I'm using Data Annotation to determine the amount of characters, I wanted to know what the largest size supported for typing text and if the correct type would be string same?

In case I wanted one that would fit as large as possible. By default I use 255.

[DisplayName("Informações Diversas")]
[Required(ErrorMessage = "Preencha as informações diversas")]
[StringLength(255, MinimumLength = 3, ErrorMessage = "As informações diversas deve ter de 3 a 255 caracteres")]
public string InformacoesDiversas{ get; set; }
    
asked by anonymous 18.01.2017 / 22:48

1 answer

1

You can use System.ComponentModel.DataAnnotations.Schema.ColumnAttribute to define that your property will be created as text in the Database.

[Column(TypeName = "text")]
public string InformacoesDiversas { get; set; }

Or through Fluent API:

modelBuilder.Entity<OTipoDaSuaEntidadeAqui>()
    .Property(e => e.InformacoesDiversas)
    .HasColumnType("text");

It is recommended to use text in the Database when you do not want to limit the size of the text.

    
27.01.2017 / 20:54