Entity Framework code first migrations throwing error

后端 未结 9 1617
再見小時候
再見小時候 2021-02-13 20:17

Here is what I did before I got this error:

  1. Installed EF (the pre release version, 6 maybe, I dunno)
  2. decided I did not want, so uninstalled that and reins
相关标签:
9条回答
  • 2021-02-13 20:30

    I believe I could figure out a solution. I had several projects in my solution.

    enter image description here

    My database logic was in SqlDataAccess. The assembly was reference in WebUI.

    I started off at the DomainLogic. Define POCOs for repository base classes there.

    Then I added SqlDataAccess project.

    and tried Enable-Migrations, Add-Migration and Update-Database command. It ran fine. After I added WebUI (an MVC 4 based web application to the project and ran the commands above. I started getting this version error.

    I unload the project WebUI and re ran the command. And it ran fine again. So, Even if it's not the best solution you might want to unload other projects leaving the atabase project in the solution and then running these commands. It worked for me. All the best!

    0 讨论(0)
  • 2021-02-13 20:32

    Yes above comment is right that worked for me.

    EntityFramework.dll needed to be in the GAC for Visual Studio to use it from the package manager.

    1. Start Visual Studio Command Prompt (ensure you started Visual Studio as Administrator) 
    2. Go to your packages directory and find the    EntityFramework package directory. 
    3. Go to lib\net45 (if targeting 4.5)    
    4. type: gacutil /i EntityFramework.dll 
    

    Note: It may be wise to restart the computer entirely at this point.

    C:\Windows\system32>cd..
    
    C:\Windows>cd..
    
    C:\>cd \packages\EntityFramework.5.0.0\lib\net45
    
    C:..\packages\EntityFramework.5.0.0\lib\net45>
    gacutil /i EntityFramework.dll
    

    This will definitively works.

    0 讨论(0)
  • 2021-02-13 20:33

    Install EF 6.1.3 and this will solve the problem.

    0 讨论(0)
  • 2021-02-13 20:39

    I also faced this problem while using using code first migration. just update the entity framework version to Entity Framework Version 6.1.3 to resolve this. using command on Package manager console "Install-Package Entity Framework -version 6.1.3"

    0 讨论(0)
  • 2021-02-13 20:44

    I was also facing same error and waste a lot of time on this error **This is only due to I updated entity framework but it gave this error so I again install Entity Framework 6.0.0 ** Error solved

    enter image description here

    0 讨论(0)
  • 2021-02-13 20:45

    Perform the following actions to resolve this issue:

    1)Uninstall Entity Framework from the package(Manage NUGET Packages).

    2)Restart Visual Studio.

    3)Re-install Entity Framework again from package manager.

    4)Add reference to the System.Data.Entity.

    5)Run the command in package manager console Enable-Migrations -ContextTypeName Movie.Models.MovieDBContext(This is a sample context).

    After this you could see the changes reflected in packages.config.

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