Visual Studio 是否有默认位置存储我的 Entity Framework 的数据库表?

Is there a default location where Visual Studio would store my database tables for Entity Framework?

我正在测试我的通用存储库,当我尝试将 Employee 实体插入我的数据库时,出现以下错误:

System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.employee_entity_dbo.person_entity_id". The conflict occurred in database "EFEmployeeEntityModelContext", table "dbo.person_entity", column 'id'.

我不知道为什么插入语句与外键约束冲突。我试图找到数据库 table "dbo.person_entity",但我不知道它在哪里。我查看了我的服务器资源管理器,没有数据连接。我也不知道服务器连接是如何设置的(我想我是在本地做的)。让我知道您是否需要更多信息,例如来自我的任何 类.

的代码

默认位置是localdb。 当您尝试在 table 中插入现有的 fk 时,或者当您尝试使用不存在的 fk

更新行时,您会遇到此异常

如果您错过了它,您应该查看 LocalDB: Where is My Database? 它描述了在哪里可以找到 LocalDB 文件以及如何使用 SQL Server Management Studio 连接到它们。


显示 LocalDB 文件所在位置的文章的屏幕截图(Windows 7+):


(来源:msdn.com

另一个显示如何连接的屏幕截图:


(来源:msdn.com


如果您是 运行 较新版本的 LocalDB(SQL 2014 层),请查看 SQL Server 2014 Express LocalDB article