Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max Length on EF property doesn't work

I have a string property on an entity with a Max Length property of 13. I can easily assign a value with length 15 to this property and only find out when I try and save changes to the database. I can see no attributes on the generated property code that indicate a max length either. What is this field for and how do I use it?

like image 466
ProfK Avatar asked Mar 18 '26 21:03

ProfK


2 Answers

see Field Max Length in Entity Framework

I had the same problem as you so I did that to get the value and apply it to my textbox or to validate...

like image 113
moi_meme Avatar answered Mar 20 '26 16:03

moi_meme


The Max Length and Fixed Length properties are ignored by the EF runtime. Do NOT expect the EF to automatically perform validation based on these properties.
These attributes are used by other consumers of the EDM, such as ASP.NET MVC 2.0 and ASP.NET Dynamic Data Controls, and, also for generating database scripts along with the StoreGeneratedPattern property.
Another usage for them would be when you are dealing at a lower level with EF; like when you are working with MetadataWorkspace class.

like image 26
Morteza Manavi Avatar answered Mar 20 '26 16:03

Morteza Manavi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!