c# - 代码优先方法、数据库位置和所有实例(v110 等)

标签 c# sql-server entity-framework visual-studio localdb

我正在关注这个 tutorial创建代码优先数据库。
安装 EF 并创建第一个基本类后,它说:

Run your application and you will see that a MigrationsCodeDemo.BlogContext database is created for you.

好吧,我有安装了所有 SQL Server 的 VS2013 Pro(VS2013 Pro 的完整安装)。
现在,正如您从下图中看到的那样,在按照教程的建议运行程序后,我找不到我的数据库。当我尝试执行本教程的迁移部分时,我确实得到了它应该得到的错误,这意味着数据库实际上已经在某处创建。我只是找不到它。
它位于哪里?
enter image description here
编辑:添加了App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <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>
</configuration>

最佳答案

物理主数据库文件位于

C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0  

数据库文件就在C:\Users\<user>

您还可以使用服务器 (localdb)\v11.0 使用 SSMS 连接到 localdb,然后从那里删除数据库。

官方文档在这里 http://msdn.microsoft.com/en-AU/library/hh510202.aspx

由 QuantumHive 编辑:
我终于发现数据库可以在名为 MSSqlLocalDb 的实例中找到, Entity Framework 默认添加到我的 App.config 中。我现在在 Visual Studio 中可视化了数据库:
enter image description here
我猜这些教程是旧的,指的是 v11.0 实例,可能和旧版本的 EF 当时默认添加了它。

关于c# - 代码优先方法、数据库位置和所有实例(v110 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25633691/

相关文章:

c# - 在将const default添加到构造函数参数后,为什么我的编译器无法识别某些方法?

sql - T-SQL : checking for email format

c# - 无法从数据网格 "Object reference not set to an instance of an object."更新项目

c# - 使用带有 Entity Framework 的 LINQ 语句以编程方式构建查询

c# - 如何缩小 UISplitView

c# - 使用 linq 返回带有 list<object> 成员的对象

c# - Excel 文件 - 它已经被另一个用户以独占方式打开,

sql - TSQL - 根据查找表在表中插入值

sql - 单向哈希函数

entity-framework - Entity Framework ,代码优先。如何覆盖生成上/下脚本