|
-
Jun 20th, 2012, 10:06 PM
#1
[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.
-
Jun 20th, 2012, 10:32 PM
#2
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.
-
Jun 21st, 2012, 01:28 AM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|