locked
MaxLength VS StringLength RRS feed

  • Question

  • User1904516115 posted

    What is the difference between MaxLength and StringLength attribute in Entity Framework?

    Monday, September 2, 2019 2:28 PM

All replies

  • User-821857111 posted

    They can both be used to configure the size of the storage for a string value in a database, but MaxLength also enforced entity validation in EF 4.1 onwards. Entity validation was not included in EF Core.

    https://www.learnentityframeworkcore.com/configuration/data-annotation-attributes/maxlength-attribute

     

    Monday, September 2, 2019 2:41 PM
  • User1904516115 posted

    I am using Code-First approach. StringLength and MaxLength both are enforcing entity validation. Can you elaborate more on differences?

    Thursday, September 12, 2019 4:51 AM
  • User-821857111 posted

    MaxLength only enables you to specify a maximum length. StringLength enables you to specify a minimum and maximum length.

    Thursday, September 12, 2019 7:20 AM