Cannot find my Entity Framework database

后端 未结 3 651
梦毁少年i
梦毁少年i 2021-01-14 21:27

I am a little confused on the code first entity framework database.

I created a new DbContext and class that I will be storing in that context, like this:

         


        
相关标签:
3条回答
  • 2021-01-14 21:58

    Yep - based on the parameter in your defaultConnectionFactory it looks like you're using the default SQL 2014 instance, not the 2012 instance.

    The (localdb)\ProjectsV12 instance is created by SQL Server Data Tools (SSDT)

    (localdb)\MSSQLLocalDB is the SQL Server 2014 LocalDB default instance name

    And (localdb)\v11.0 is the SQL Server 2012 LocalDB default instance name

    0 讨论(0)
  • 2021-01-14 22:06

    You need to set your database server as (LocalDB)\MSSQLLocalDB. This is a change made to EF 6.1.1 onwards. The MSSQLLocalDB is mentioned in your parameter. More details on the change can be found here https://entityframework.codeplex.com/workitem/2246

    MSSQLLocalDB is the default instance name on SQL Server 2014 whereas v11.0 is the default Instance name on SQL Server 2012

    0 讨论(0)
  • 2021-01-14 22:19
    using (var db = new BloggingContext()) 
    { 
      var connectionString = db.Database.Connection.ConnectionString;
      Console.WriteLine(connectionString); 
    }
    

    The above code uses the Microsoft example; for BloggingContext substitute your DbContext class. It will give you the connection string that the entity framework is using, which includes the instance name.

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