Using Entity Framework Migrations with MS SQL Server



I'm attempting to utilise the local (default) instance of SQL Server with Entity Framework Migrations.

This is how I have entity framework configured:

    <add name="Demo.Data.MyContext"
       connectionString="Data Source=(local);Initial Catalog=Connector;    
       Integrated Security=True;MultipleActiveResultSets=True" />
  <section name="entityFramework" 
        type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

This is the context class:

namespace Demo.Data
  public class MyContext : DbContext

According to what I've read in the documentation, EF will be able to find a connection string if its name is the same as the context.

However, when I carry out the command:

PM> Update-Database -verbose

The result is this:

Using StartUp project 'Demo'.
Using NuGet project 'Demo.Data'.
Target database is: 'Demo.Data.MyContext' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).

Why does it keep choosing to target.SQLEXPRESS is the question.

How should my app.config be set up such that EF points to my own SQL Server locally?

9/10/2016 8:20:25 PM

Popular Answer

Evidently, utilising the PM console, there is a method to make it work:

In Visual Studio, the project containing the Entity Framework migrations package must be chosen as the "starting project." Simply choosing the project as the "Default project" in the PM console is insufficient.

Additionally, utilising the

PM> Update-Database -StartUpProjectName "Demo.Data"

On the console, a switch.

10/4/2016 11:08:30 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow