Entity Framework Code First 默认数据库位置

3
我正在尝试跟随 http://msdn.microsoft.com/en-us/data/jj193542 上的视频教程,使用 Visual Studio 2012 Express for Desktop。我创建了 POCO 和 DbContext,运行了一些示例查询,它可以工作。但是我没有提供任何连接字符串。那么数据库在哪里呢?(可能是 sdf 或 mdf 文件?)
在教程期间,那个人使用 SQL Server Object Explorer 查看数据库,但我在 VS Express 中找不到该视图。
供参考,这是生成的默认 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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>
2个回答

8
如果安装了 SQL Express(包含在 Visual Studio 2010 中),则数据库将创建在本地的 SQL Express 实例上(.\SQLEXPRESS)。如果未安装 SQL Express,则 Code First 将尝试使用 LocalDb ((localdb)\v11.0) - LocalDb 包含在 Visual Studio 2012 中。
更多信息请参考:http://msdn.microsoft.com/en-us/data/jj591621.aspx

1
对于 Visual Studio 2015,它似乎默认为 (LocalDb)\mssqllocaldb - default

0

@Default 是正确的,在 VS 2015 和 2017 中默认的 SQL Server 是 (LocalDb)\mssqllocaldb


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接