【问题标题】:Entity Framework Code First Default Database Location实体框架代码优先默认数据库位置
【发布时间】:2013-03-21 09:19:50
【问题描述】:

我正在尝试使用 Visual Studio 2012 Express for Desktop 来关注 http://msdn.microsoft.com/en-us/data/jj193542 上的视频教程。

我创建了 POCO 和一个 DbContext,运行了一些示例查询并且它起作用了。但我没有提供任何连接字符串。那么数据库在哪里呢? (可能是 sdf 或 mdf 文件?)

在教程中,该人使用 SQL Server 对象资源管理器查看数据库,但我在 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>

【问题讨论】:

    标签: entity-framework visual-studio-2012


    【解决方案1】:

    “如果安装了 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

    【讨论】:

    • 对于 Visual Studio 2015,它似乎默认为 (LocalDb)\mssqllocaldb
    【解决方案2】:

    @Default 正确,VS 2015 和 2017 中默认的 SQL server 为(LocalDb)\mssqllocaldb

    【讨论】:

      猜你喜欢
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多