We'll start by using the NuGet package manager (automatically installed by ASP.NET MVC 3) to add the EFCodeFirst library to the MvcMovie project. This library lets us use the code-first approach.

Warning:  You must stop debugging before you access the NuGet package manager. If you access NuGet while you are still debugging, you'll get the error message and the Add Library Package Reference... menu item will disappear. You must then exit Visual Web Developer and restart the project.

 

From the Tools menu, select Library Package Manager and then Add Library Package Reference.

Using NuGet to Install EFCodeFirst_.NET

The Add Library Package Reference dialog box appears.

Using NuGet to Install EFCodeFirst_职场_02

By default, All is selected in the left pane. Because no packages are installed, the center pane shows No items found. Click Online in the left pane.

Using NuGet to Install EFCodeFirst_MVC_03

NuGet queries the server for all available packages.

Using NuGet to Install EFCodeFirst_休闲_04

There are hundreds of packages available. We're interested in the EFCodeFirst package. In the search box, enter "EFCode". In the search results, select the EFCodeFirst package and click the Install button.

Using NuGet to Install EFCodeFirst_MVC_05

After the package installs, click Close. The installation process downloaded the EFCodeFirst library and added it to the MvcMovie project. The EFCodeFirst library is contained in the EntityFramework assembly.

Using NuGet to Install EFCodeFirst_.NET_06