Error 3004, mapping error with EF

谁说我不能喝 提交于 2019-12-23 08:47:56

问题


Ok since my of my issues have been resolved,I was flying through the code, until now: I've now run into one I cant even find anything on Google for it. Here's the text of the error:

Error 3004: Problem in mapping

fragments starting at line 937:No mapping specified for properties StoreItem.ItemPrice in Set StoreItems. An Entity with Key (PK) will not round-trip when: Entity is type [psychoco_GodsCreationTaxidermyModel.StoreItem] F:\Projects\GodsCreationTaxidermySVN\GodsCreationTaxidermy.Data\GCTEntities.edmx 938 945 GodsCreationTaxidermy.Data

Of you need any code samples let me know


回答1:


The error means that your table imported to the model contains additional column ItemPrice which is not mapped to your entity.




回答2:


I ran into the same error, using the database first approach. The cause was that when I added an association through the designer, EF decided to add a synthetic field to my principal, based on whatever key relationship I had defined. If you are doing database first, check if ItemPrice on StoreItem is a real database field, or if EF just decided to generate it for you.




回答3:


Just another cause of this that we came across: say we have two developers, A and B.

  1. Dev A adds columns (say "newcol") to a table (say "mytable") in the database project then updates their model. All builds well, database has mytable.newcol and the model reflects this.
  2. Dev B pulls/syncs but forgets to publish the changes to their local database. The model has mytable.newcol but their local database doesn't.
  3. Dev B then changes the model in some way and updates it from the database, VS sees that mytable.newcol doesn't exist so it becomes unlinked.

  4. Dev B realises their error and publishes the database changes.

  5. Dev B then updates the model from the database again. Now VS sees the mytable.newcol column in the database and creates a mytable.newcol1 (note the suffix) that is linked to the database column, since it already had an unlinked newcol in the model.

    For Dev B, VS then complains that mytable.newcol isn't mapped and fails.

Solution - to fix, remove mytable.newcol from the model, rename mytable.newcol1 to newcol... or revert to where you were and remember to publish the database before updating the model!

Hope this helps someone.



来源:https://stackoverflow.com/questions/5931521/error-3004-mapping-error-with-ef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!