[RESOLVED] Entity Framework: saving empty string as dbnull?
I'm using EntityFramework 4.3 Code First. How can I save an empty string value as NULL in the database? EF is throwing a System.Data.Entity.Validation.DbEntityValidationException whenever I attempt to save an entity with a null string value for one of it's properties.
Re: Entity Framework: saving empty string as dbnull?
I haven't used EF 4.3 or Code First but I can't imagine that it's that much different in this fundamental regard. Is the database column generated to map to your string property nullable? If not then that would explain the exception. In that case you presumably need to decorate the property with an appropriate attribute to specify that it is nullable. I would have expected nullable to be the default though. That is supported by the existence of the Required attribute, which basically means not nullable.
Re: Entity Framework: saving empty string as dbnull?
Thanks. I had .IsRequired() set for that column in the EF mapping class. Don't know how I missed that one.