gpt4 book ai didi

entity-framework-5 - 我的数据库在哪里,如何查看?

转载 作者:行者123 更新时间:2023-12-04 00:56:35 24 4
gpt4 key购买 nike

我刚刚创建了一个全新的应用程序,通过 NuGet 添加了 EntityFramework 5,创建了一个非常基本的 DbContext 并将一些数据保存到其中。

我的数据究竟在哪里,如何查看?未修改 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" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>

并通过检查 db对象我可以看到我的连接字符串是
Data Source=(localdb)\\v11.0;Initial Catalog=ImageSignature.ImageContext;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFrameworkMUE

但所有这些在我看来都是胡言乱语。我来自 MySQL 背景。

我的数据库究竟在哪里,我如何查看它?我在 VS2012 的“服务器资源管理器”下看不到任何相关内容。

最佳答案

This文章应该回答你的问题。

The configuration section allows you to specify a default connection factory that Code First should use to locate a database to use for a context. The default connection factory is only used when no connection string has been added to the configuration file for a context.

When you installed the EF NuGet package a default connection factory was registered that points to either SQL Express or LocalDb, depending on which one you have installed.



从您的配置来看,您似乎正在使用与 LocalDb 的连接, which is a minimalist version of SQL used for development .

您可以尝试使用 Visual Studio 中的内置服务器资源管理器来访问该数据库,但是,正如您所写的,它可能“开箱即用”不可见。因此,您可能需要在服务器资源管理器中创建新连接才能查看内容。

编辑:

我不得不用 VS2012 启动 VMware Windows 8 才能真正回答“驱动器上的数据库在哪里”的问题。
LocalDb创建 mdfldf C:\Users\<USER NAME>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0 中的文件

Screenshot from my VM

至于通过服务器浏览器连接到它,我可以通过输入 (LocalDb)\v11.0查看数据库。作为服务器地址,然后从您的应用程序(带有命名空间)中选择名称类似于数据上下文名称的数据库。

我找到的所有这些信息 here .

请注意,在您发布的代码中 here似乎您正在使用 Database.SetInitializer(new DropCreateDatabaseAlways<ImageContext>()); 在应用程序开始时重建数据库.当然,这在第一次运行应用程序时很好(因此数据库实际上已创建),但随后的重新运行将清除数据并从新的石板开始。在我使用服务器资源管理器连接到数据库后,我实际上无法执行此代码,因为“数据库已在使用中”。您可能需要重新考虑在服务器浏览器中保持连接打开或更改该行代码。

关于entity-framework-5 - 我的数据库在哪里,如何查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16706852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com