Search code examples
entity-frameworkef-database-first

How to prevent Entity Framework from converting empty strings to null in database-first approach


I have to insert empty strings in a non-nullable varchar field in an oracle db. The property of the object I'm trying to save is set to empty string, but when I call SaveChanges I get an error because EF converts my empty string to null. I know that, in code-first approach, there you can use ConvertEmptyStringToNull=false: is there a way to achieve the same behavior with database-first approach?


Solution

  • It appears that in Oracle (at least for now) the empty string is treated as null. Therefore there is no way to save an empty string in a varchar field.

    Note:Oracle Database currently treats a character value with a length of zero as null. However, this may not continue to be true in future releases, and Oracle recommends that you do not treat empty strings the same as nulls.

    Source