Number of members in conceptual type does not match with number of members on object side type

后端 未结 9 770
梦如初夏
梦如初夏 2020-12-06 09:43

I\'m using .net framework 3.5 SP1.

After adding a column to one table in Sql Server (as well as changing an existing column from allowing nulls to not nullable), I c

相关标签:
9条回答
  • 2020-12-06 09:48

    This error can also happen if the EDMX file was changed outside Visual Studio. Right click on the EDMX file and click "Run Custom Tool"

    0 讨论(0)
  • 2020-12-06 09:48

    Here's a nightmare scenario that I just experienced: I have an MVC2 website and a WCF service that are built separately, but share a configuration. Within both projects, I used the same Entity Container Name; therefore I picked up the same connection string for both projects. Eventually the metadata got out of sync between the two and caused this error. The obvious solution was to not use the same Entity Container Name in the two projects; changing to a different name allowed me to specify unique connection strings, and therefore metadata, for each component which avoided the problem.

    Now that I figured it out, it's obvious, but I had a tense hour or two!

    0 讨论(0)
  • 2020-12-06 09:50

    This seems a little verbose for a comment so I'm adding this as another answer:

    In response Craig's suggestion I opened the edmx file in an XML viewer and removed all references to Axis_t (including the associations due to Foreign Keys). From the entire file.

    I then "updated" the model by opening the edmx file as the GUI interface, right-click | refresh from database | Add (tab) which now only lists the Axis_t table. I added the table which seemed to work fine and included my new column and the column was mapped correctly.

    I then ran the project to the same result. Same error as posted above.

    I have now reverted back to what was in source control as well as changing the database columns (new one and modified one) as nullable. The project runs fine. I still have not successfully been able to implement the new DB column in EF. It behaves as if there is some stored/compiled version of the model which is not being updated via the "update" process.

    0 讨论(0)
  • 2020-12-06 09:53

    When changing a foreign key from nullable to non-nullable (or vice-versa), be sure to change the association multiplicity from 0..1 to 1 (or vice-versa). The designer sometimes misses this in an update from the database.

    0 讨论(0)
  • 2020-12-06 09:56
    • Right click on your edmx file and open with XML.
    • Find the incorrect data types and change them.
    • Save file.

    This worked for me.

    0 讨论(0)
  • 2020-12-06 10:01

    I had this same issue for hours. Found that in my Designer.cs file one of the properties of my entity was missing its attributes. (Don't know how this happened?)

     [EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
     [DataMemberAttribute()]
     public global::System.Int32 ContractCapacity
    

    Now the error message makes sense, this was the missing DataMember. Once the attribute was added IT WORKED!!!

    0 讨论(0)
提交回复
热议问题