Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can’t find the new Code First Entity Framework Database

Basically I am using the Entity Framework Code First technique. The code I wrote works. However, I can’t find the newly created database in SQL Server Management Studio. Where is it? What IDE should I be using to see the newly created database and tables. I ran the following code with no problem: IsoLocationContext db = new IsoLocationContext();

   Address address = new Address();

   address.TrackingNumber = "123";

   db.Addresses.Add(address);
   db.SaveChanges();

However, I can’t seem to find the database and tables. I did tried to refresh the list of databases.
I then added the following the line just to make sure the data was actually going to the database.

   IList<Address> addresses = db.Addresses.ToList();

The above processing worked as well. I also stopped and started the server and rebooted the whole machine. Just to make sure the data wasn’t being stored in memory. Everything worked as expected. I also ran the Profiler against the server while I was running the app and I saw no entries in the Trace.

Please tell me, what I am missing. This is driving me crazy.

Also I am using SQL Server 2008 R2 Developer / Client version.

like image 676
Richard Avatar asked Dec 06 '11 19:12

Richard


People also ask

How do I change code first to database first?

There is no way to convert your code-first classes into database-first classes. Creating the model from the database will create a whole new set of classes, regardless of the presence of your code-first classes. However, you might not want to delete your code-first classes right away.

How do I code first in Entity Framework?

Step 1 − First, create the console application from File → New → Project… Step 2 − Select Windows from the left pane and Console Application from the template pane. Step 3 − Enter EFCodeFirstDemo as the name and select OK. Step 4 − Right-click on your project in the solution explorer and select Manage NuGet Packages…

How do you use code first when an existing database schema?

To use code-first for an existing database, right click on your project in Visual Studio -> Add -> New Item.. Select ADO.NET Entity Data Model in the Add New Item dialog box and specify the model name (this will be a context class name) and click on Add.


1 Answers

Try looking at your connection string like this:

 ((IObjectContextAdapter)db).ObjectContext.Connection.ConnectionString
like image 56
John Gibb Avatar answered Sep 21 '22 10:09

John Gibb