Join us Now |  Forgot Password? | Forgot UserName?

Asp.Net MVC

Learn step by step

Working with SQL Server LocalDB

Entity Framework Code First recognize that the database connection string that was allocate pointed to a TutOnDemo database that did not occur yet, so Code First generate the database automatically. We can confirm that it is been generated by inspect in the App_Data folder. If we do not see the TutOnDemo.mdf file, click the Show All Files button in the Solution Explorer toolbar, click the Refresh button, and then elaborate the App_Data folder.

Double-click TutOnDemo.mdf to open DATABASE EXPLORER, then elaborate the Tables folder to see the TutOnDemo table.

Hint: If  the database explorer does not visible, from the TOOLS menu,chooseConnect to Database,then cancel the Choose Data Source dialog.This will force open the database explorer.

Note: If we are using VWD or Visual Studio 2012 and get an error similar to any of the following following:

  • The database 'C:\Webs\MVC4\TutOn\APP_DATA\TutOnDemo.MDF' cannot be opened because it is not supporting version. This server supports older version 655. A downgrade path is not assist.
  • "InvalidOperation Exception was uncontrolled" The supplied SqlConnection does not identify an initial catalog.

You required to install the SQL Server Data Tools and LocalDB.Justify the TutOnDemoContext connection string described on the previous page.

Right-click the TutOnDemo table and choose Show Table Data to see the data you generated.

Right-click the TutOnDemo table and choose Open Table Definition to see the table order that Entity Framework Code First generated for you.

Notice how the schema of the TutOnDemo table maps to the TutOnDemo class you generated earlier. Entity Framework Code First automatically generated this schema for you based on your TutOnDemo class.

When we are finished,close the connection by right clicking TutOnDemoContext and choosing Close Connection.(If we do not close the connection, we might get an error the next time you run the project).

Related Videos