locked
Nullable Property Problem Question RRS feed

  • Question

  • Although neither in my class nor in my EF config (Code First fluen api - required) file I have mentioned the LastUpdatedDateTime must be non-null I get an error (see hereunder) that the property can't be a null value?!

    "The 'LastUpdatedDateTime' property on 'Medium' could not be set to a 'null' value. You must set this property to a non-null value of type 'DateTime'"

    Can someone explain  why I get this error?

    Thanks.
    Guy

    Sunday, February 12, 2012 8:25 PM

Answers

  • Please post the class that the field 'LastUpdatedDateTime' is part of and any configurations made with fluent API's to the class and its members. Also post the query and the line of code that causes the exception.

    Thanks;


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alan_chen Wednesday, March 14, 2012 6:55 AM
    Monday, February 13, 2012 2:35 PM

All replies

  • Hi Guy;

    You state, "(see hereunder)", but non was posted.

    The error is most likely that your Code First Model has a field of LastUpdatedDateTime with a data type of DateTime and when you do an insert you do not fill that field with a valid DateTime object. In order to make that field nullable in the db you need to make that field DateTime? in your code.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by Alan_chen Monday, February 13, 2012 9:05 AM
    Sunday, February 12, 2012 10:46 PM
  • thanks.

    The message was: "The 'LastUpdatedDateTime' property on 'Medium' could not be set to a 'null' value. You must set this property to a non-null value of type 'DateTime'"

    Although I didn't marked in my class (data annotaions), nor in my EF config file (code first fluent api) nor in my database that the DateTime value of LastUpdatedDateTime is mandatory/required I must in my class define the property as nullable??

    Thanks.

    Guy

    Monday, February 13, 2012 10:24 AM
  • Please post the class that the field 'LastUpdatedDateTime' is part of and any configurations made with fluent API's to the class and its members. Also post the query and the line of code that causes the exception.

    Thanks;


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alan_chen Wednesday, March 14, 2012 6:55 AM
    Monday, February 13, 2012 2:35 PM