none
Problem changing a value from nullable to non-nullable. RRS feed

  • Question

  • Hello,

    In my database I add an int foreign key that was allow null values. I changed that so that it does not accept null values.

    Since then, when I run my C# Winforms application, I get the exception:

    Model1.msl(15,10) : error 3031: Problem in mapping fragments starting at line 15:Non-nullable column Addresses.addr_Contact_Id in table Addresses is mapped to a nullable entity property.

    when I select data.

     

    In my Model1.edmx file, I have used 'Update Model From Database ...'

    --> no change

     

    I checked the field in Model1.edmx, it has 'Nullable = none', so I changed it manually to 'Nullable = false'.

    But when I do that all my datasources based on this edmx files say '[datasource] is no longer availble. Verify the class name is correct and the reference to this class is still valid.

     

    So, how do I change the nullable state of a value in from the DB to the app ?

     

    Thank you for your help.

    Tuesday, December 20, 2011 12:04 PM

Answers

  • Delete the offending table from the edmx gui and then update using the wizard (expand tables) and add your updated table.  Rebuild your solution.
    • Proposed as answer by buthfa Tuesday, December 20, 2011 3:23 PM
    • Marked as answer by ThomasMSN Tuesday, December 20, 2011 10:12 PM
    Tuesday, December 20, 2011 3:22 PM

All replies

  • Delete the offending table from the edmx gui and then update using the wizard (expand tables) and add your updated table.  Rebuild your solution.
    • Proposed as answer by buthfa Tuesday, December 20, 2011 3:23 PM
    • Marked as answer by ThomasMSN Tuesday, December 20, 2011 10:12 PM
    Tuesday, December 20, 2011 3:22 PM
  • Thank you.

    This was useful just right now, but doing this, you can lose custom Navigation Properties ...

    Tuesday, December 20, 2011 10:12 PM
  • If you create your relationships in the database it will keep/apply them when you update the table.
    Wednesday, December 21, 2011 8:51 AM