Entity Framework Code First Migrations

戏子无情 提交于 2019-12-06 05:22:04

问题


on running following command

pm> Update-Database

getting following error

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.SqlServer.SqlProviderServices' threw an exception. ---> System.TypeLoadException: Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' from assembly 'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' does not have an implementation.


回答1:


Your EF version and Project Version is not Equal. your Entity Framework is ver 6 of .Net 4 but your project use .net 4.5 Project by .net version 4.5 must use EF for .Net4.5




回答2:


I had the same problem (EF 6.1.3 & net462) and I tried all the answers, but nothing fixed the problem. When I eventually switched to Release configuration, it worked liek a charm.

Not sure what's wrong with Debug, since they are almost identically, except for debug trace etc.

Hope this helps other people in the future.




回答3:


Not the ideal solution, but I switched back to Entity Framework 5.0.0 and the problem went away. Found this useful link.




回答4:


Hi I had a similar problem. After a long time I found that one project referenced Entity Framework version 6.1.1 and in another project version 6.1.3 is referenced in same solution. I removed 6.1.3 from the package manager console. Problem is finally solved.

Hope this will help someone




回答5:


I had the same problem. After spending some hours to fix this. What fixed the problem was: I closed the project, created a new one with the same name, copied my folders and classes I created to the new project and downloaded the packages I needed through nuget. Then Add-Migration ...... everything went well afterwards.



来源:https://stackoverflow.com/questions/20513621/entity-framework-code-first-migrations

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