Max. EF object length not working

I have a string property for an object with a Max Length property of 13. I can easily set this value to a value of length 15 and only find out when I try to save the changes to the database. I do not see any attributes in the generated property code, which also indicates the maximum length. What is this field and how to use it?

+3
source share
2 answers

Properties Max. length and fixed length are ignored by the EF startup environment. DO NOT expect EF to automatically validate based on these properties.
These attributes are used by other EDM users, such as ASP.NET MVC 2.0 and ASP.NET Dynamic Data Controls, as well as to create database scripts along with the StoreGeneratedPattern property .
Another use for them is when you work at a lower level with EF; for example, when you work with the MetadataWorkspace class.

+2
source

Source: https://habr.com/ru/post/1765883/


All Articles