This row causes the exception:
var query = from customer in ctx.Customers select customer; Exception:
An unhandled exception of type 'System.Data.Entity.Core.ProviderIncompatibleException' occurred in EntityFramework.dll
An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
Connection string from Database.Connection.ConnectionString:
Data Source=.\SQLEXPRESS;Initial Catalog=Customer.CustomersContext;Integrated Security=True;MultipleActiveResultSets=True App.config:
<?xml version="1.0" encoding="utf-8"?> <configuration> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> <connectionStrings> <add name="Customer.CustomersContext" providerName="System.Data.SqlClient" connectionString="Data Source=(localdb)\Projects;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" /> </connectionStrings> </configuration> Context class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.Entity; namespace Customer { class CustomersContext : DbContext { public CustomersContext() : base("Customer.CustomersContext") { System.Console.WriteLine(Database.Connection.ConnectionString); } public DbSet<CustomerDb> Customers { get; set; } public DbSet<Contact> Contacts { get; set; } } } You can see I even tried to pass connection string name from app.config to context constructor (localdb should be used), but the printed connection string is still SQLExpress.
SqlConnectionFactoryas opposed to theLocalDbConnectionFactory, which uses a slightly different connection string format.