Entity Framework 6.1 : The given key was not present in the dictionary

倾然丶 夕夏残阳落幕 提交于 2019-12-06 06:39:58

It's a bug. It happened because you have rename your pocos and/or dbsetnames.

Retry dbfirst without rename and you'll certainly bulk it!

This happened to me in the following situation:

  • DB first
  • no manually renamed entities after updating the model from the database.
  • a table called Users
  • 'Pluralize or singularize generated object names' enabled

I resolved it by renaming the table to User.

NB: I dug a little with .Net Reflector to get to a solution and I assume that the EntityFramework.MappingAPI is trying to find the table User, because the the POCO is called User, although didn't dig further once I had it fixed.

For me the error was caused by the Column attribute used on a random entity. E.g.:

[Column("LanguageName")]

public string Name { get; set; }

It is clearly a bug in the BulkInsert columns mapping.

As a side note: the developer that didn't check the key in that dictionary should feel bad. He has wasted a lot of time for us.

Happy codding.

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