如何防止 Entity Framework 在数据库优先方法中将空字符串转换为 null

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

我必须在 oracle 数据库的不可为 null 的 varchar 字段中插入空字符串。 我要保存的对象的 属性 设置为 空字符串 ,但是当我调用 SaveChanges 时出现错误因为 EF 将我的空字符串转换为 null。 我知道,在代码优先的方法中,你可以使用 ConvertEmptyStringToNull=false:有没有办法用 database-first[=17= 实现相同的行为] 方法?

似乎在 Oracle 中(至少目前)空字符串被视为 null。 因此无法在 varchar 字段中保存空字符串。

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