Entity Framework Code First Migrations failing on Wrong Provider (3.5 instead of 4.0)

后端 未结 2 1744
迷失自我
迷失自我 2021-01-16 10:33

I am trying to add a migration (for the first time) to a project using Entity Framework 6.0.2 for SQL Server Compact (code first). The application is having no problems comm

相关标签:
2条回答
  • 2021-01-16 11:12

    I just spent half a day trying to get SqlServerCe 4.0 SP1 aka 4.0.0.1 to work without above exceptions. Finally solved, hope it'd help someone else.

    1. Install SqlServerCe 4.0 SP1 either from here or via web platform installer
    2. Copy "Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private" amd64 and x86 to bin folder of your web app and include them in project (so that they become deployable)

    3. Do not copy "System.Data.SqlServerCe.dll" and "System.Data.SqlServerCe.Entity.dll"

    4. nuget "Microsoft.SqlServer.Compact" was installed instead of obsolete "SqlServerCompact"
    5. project references do not contain System.Data.SqlServerCe, however it would exist in bin folder after project clean/build procedure
    6. web.config

    answers above are valid BUT "Version=4.0.0.1" didn't work for me, instead just "4.0"

    <system.data>
        <DbProviderFactories>
          <remove invariant="System.Data.SqlServerCe.4.0" />
          <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>
    </system.data>
    
    0 讨论(0)
  • 2021-01-16 11:33

    Remove the binding redirect. It looks like you are trying to use private deployement, but are you using the correct System.data.SqlServerCe.dll (check the Assembly version). if it is 4.0.0.0 and not 4.0.0.1, then change to DbProviderfactories setting to point to the correct assembly version

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