locked
Non-nullable columns in DB becomes "nullable: (none)" RRS feed

  • Question

  • Hi,

    As mentioned in the title, columns (in fact FKs) which are not nullable in the DB are mapped to properties which are "nullable: none", neither false, nor true..

    This causes problems when updating the model from the database:

    Error    30    Error 3031: Problem in mapping fragments starting at line 9416:Non-nullable column ProjectActivities.TimePlanID in table ProjectActivities is mapped to a nullable entity property."

    Why is this? And how can I solve this issue?

    Both the primary and foreign keys are non-nullable in the Database.

    Friday, March 19, 2010 9:46 AM

Answers

  • Hi Jeremy,

    When you generated the EDMX, were the columns already not nullable?

    I get the same problem when I change an existing column in the DB from a nullable to not nullable then update the EDMX. What I do is change the column's Nullable property in the designer from (None) to False.

    This usually works.

    Wednesday, March 24, 2010 3:35 AM

All replies

  • Hi Jeremy,

    When you generated the EDMX, were the columns already not nullable?

    I get the same problem when I change an existing column in the DB from a nullable to not nullable then update the EDMX. What I do is change the column's Nullable property in the designer from (None) to False.

    This usually works.

    Wednesday, March 24, 2010 3:35 AM
  • This is correct - currently, the update model wizard does not synchronize the Nullable value from the database to the model (we were trying to touch the model as little as possible. In this case, too little, it appears. Something we want to fix in a future release.)

    Note that a (None) value simply means that no value is specified in the XML, which the runtime reads as True. Setting it to False is the right approach.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, April 8, 2010 11:08 PM
    Moderator
  • Thanks for this info Migs.

    This is serious issue with Entity Framework, that it is not updating the model completely. I modified some of my tables by changing columns from null to not-null, and was trying to update the model, but it was giving errors. At least this is issue with VS2008 SP1, dont know about VS2010\EF4.

    Tuesday, May 4, 2010 10:53 AM
  • I believe is still a problem with VS2010\EF4 as I am still getting the problem although I understand the concern to NOT overly update the model.

    There may be a 2nd step you have to do if you manually change your Column from Nullable to Not Nullable.

    Step 1: Change Column from Nullable to Not Nullable

    Model1.edmx > MyModel > Entity Types > MyTable > MyColumn : Properties : Nullable from (None) to False .

    This then causees the model to fail to build because of a new error which causes the Model not to build at all!  Happily, the first error in your error list will point to the problem, e.g.:

    "Error 113: Multiplicity conflicts with the referential constraint in Role 'TextStore' in relationship 'FK_Ass_Action_ActionTextStore'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.    D:\Projects\...\AssessmentClassLib\Model1.edmx    2124    11    AssessmentClassLib"

    Step 2: Fix End 1 Multiplicity on any dependant relationships

    This error is that the FK relationship between the now Not Null field has End1 Multiplicity = "0..1" and End 2 Multiplicity is "*" and End1 Multiplicity should be set to "1"

     

    Double click the first error in your error list (e.g. error 113 message above).  This will highlight a relationship in the visual model.

    Properties the relationship and update End 1 Multiplicity to "1 (One of ...)"

    • Proposed as answer by TimK_ Tuesday, July 27, 2010 5:18 PM
    Friday, May 28, 2010 1:58 PM
  • Thank you BloodBaz!! That worked perfectly.
    Ron
    Thursday, November 3, 2011 3:15 PM
  • Its Great... thankyou ..

    Its working fine

    Monday, November 14, 2011 7:58 AM