ErikEJ / EntityFramework6PowerTools

This is the codebase for Entity Framework 6 Power Tools Community Edition, and modern EF 6 providers for SQL Server and SQL Server Compact
Other
183 stars 27 forks source link

ErikEJ.EntityFramework.SqlServer is not working in a .net 4.8 console application #110

Closed arman-m closed 1 year ago

arman-m commented 1 year ago

I have an existing ASP.NET WebForms application which I converted to use Microsoft.Data.SqlClient with ErikEJ.EntityFramework.SqlServer library and it is working, although to Regenerate Views I have to change provider in the connection string back to System.Data.SqlClient. I have another console application which is using the same EF context but every time I try to query the context I get the following error The current model no longer matches the model used to pre-generate the mapping views, as indicated by the ViewsForBaseEntitySets8660e3bff6fec2d8af82f3fdbe8da4e92b2ca78ffb8ccc99fdee86d39b2dfd55.MappingHashValue property. Pre-generated mapping views must be either regenerated using the current model or removed if mapping views generated at runtime should be used instead. See http://go.microsoft.com/fwlink/?LinkId=318050 for more information on Entity Framework mapping views. This is ONLY happening in the console app. The WebForms application works fine. I use XML/App.Config based configuration:

     <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />    
    </configSections>
    <entityFramework>
        <providers>     
            <provider invariantName="Microsoft.Data.SqlClient" type="System.Data.Entity.SqlServer.MicrosoftSqlProviderServices, ErikEJ.EntityFramework.SqlServer" />
        </providers>
    </entityFramework>
    <system.data>
        <DbProviderFactories>
           <add name="SqlClient Data Provider"
             invariant="Microsoft.Data.SqlClient"
             description=".NET Framework Data Provider for SqlServer"
             type="Microsoft.Data.SqlClient.SqlClientFactory, Microsoft.Data.SqlClient" />
        </DbProviderFactories>
    </system.data>

I have installed EntityFramework 6.4, ErikEJ.EntityFramework.SqlServer and Microsoft.Data.SqlClient nuget packages in the console app. I have no idea how to get around this issue. Any help would be appreciated.

ErikEJ commented 1 year ago

I need you to share a repro

arman-m commented 1 year ago

Thanks, Erik for taking the time. While I was trying to create a smaller project to illustrate the issue, I figured out what's causing it. We have 2 classes inherited from DbContextand in their default constructor both of them were using a named connection string with the same name. I renamed one of them and everything started working as before.