This will allow you to save the entity with an empty string in this field.[DisplayFormat(ConvertEmptyStringToNull=false)]
This blog is titled the way it is, because this is the method by which I came to learn most of the following information. 🤪
Tuesday, September 24, 2013
EF Empty Strings in Non-Nullable Fields
When using Entity Framework, sometimes it is desirable to have non-nullable string fields. The problem is that if the user leaves the field blank, EF will complain that a value is required in the field. To fix this, create a metadata class for the entity you are working with. Then decorate the field with this attribute:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment