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.
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.
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…
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.
Try looking at your connection string like this:
((IObjectContextAdapter)db).ObjectContext.Connection.ConnectionString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With