Entity Framework Code First Migrations

2020-07-18 09:24发布

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.

5条回答
对你真心纯属浪费
2楼-- · 2020-07-18 10:04

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

查看更多
迷人小祖宗
3楼-- · 2020-07-18 10:06

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.

查看更多
Anthone
4楼-- · 2020-07-18 10:11

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

查看更多
Anthone
5楼-- · 2020-07-18 10:14

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

查看更多
萌系小妹纸
6楼-- · 2020-07-18 10:17

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.

查看更多
登录 后发表回答