Drew
Drew

Reputation: 1337

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

I am testing my generic repository and when I try to insert an Employee entity into my database, I get the following error:

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'.

I have no idea why the insert statement conflicted with the foreign key constraint. I am trying to find the database table "dbo.person_entity", but I have no idea where that is. I looked in my server explorer and there are no data connections. I don't know how the server connection was setup either (I think I'm doing it locally). Let me know if you need anymore information, such as code from any of my classes.

Upvotes: 0

Views: 4922

Answers (2)

Jaanus Varus
Jaanus Varus

Reputation: 3573

In case you have missed it, you should check out LocalDB: Where is My Database? It describes where to find LocalDB files and how to connect to them using SQL Server Management Studio.


Screenshot from the article showing where the LocalDB files are located (Windows 7+):

localdb location
(source: msdn.com)

Another screenshot showing how to connect:

SSMS
(source: msdn.com)


If you are running a fresher version of LocalDB (SQL 2014 tier), check out SQL Server 2014 Express LocalDB article.

Upvotes: 3

Bilel Chaouadi
Bilel Chaouadi

Reputation: 933

The default location is localdb. You get this exception when you try to insert an existing fk in your table,or when yo try to update a row using a non existing fk

Upvotes: 1

Related Questions