Results 1 to 3 of 3

Thread: [RESOLVED] Entity Framework: saving empty string as dbnull?

  1. #1

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Resolved [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.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    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.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width