How to fix Entity Framework’s “Schema specified is not valid” error

I am using Entity Framework 6.1.3 in my Data Access Layer. Once the Model.edmx is added to the project, configured with a database and build it, it builds fine.

But when I try to use the Data Access Layer in the UI, here is the error that is thrown.

EntityFrameworkError

The error mentions adding provider in the entityFramework section in the app.config file but I already had this:

<entityFramework>
   <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
     <parameters>
       <parameter value="mssqllocaldb" />
     </parameters>
   </defaultConnectionFactory>
   <providers>
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
   </providers>
</entityFramework>

After some research, I found a fix. I added the following line to the Model.Contenxt.cs file in the using’s section and it fixed my error.

using SqlProviderServices = System.Data.Entity.SqlServer.SqlProviderServices;

Keep in mind that Model.Context.cs file is auto-generated each time the Model.edmx is changed. So the above line of code has to be added to the file each time.

Please suggest if anyone has a better way of fixing this issue.

Leave a comment