标签:
In Solution Explorer, right click the Models folder > Add > Class. Name the class Movie and add the following properties:
using System; namespace MvcMovie.Models { public class Movie { public int ID { get; set; } public string Title { get; set; } public DateTime ReleaseDate { get; set; } public string Genre { get; set; } public decimal Price { get; set; } } }
n addition to the properties you’d expect to model a movie, the ID
field is required by the DB for the primary key.
Build the project.
If you don’t build the app, you’ll get an error in the next section.
We’ve finally added a Model to our MVC app.
In Solution Explorer, right-click the Controllers folder > Add > Controller.
In the Add Scaffold dialog, tap MVC Controller with views, using Entity Framework > Add.
Complete the Add Controller dialog
The Visual Studio scaffolding engine creates the following:
Visual Studio automatically created the CRUD (create, read, update, and delete) action methods and views for you (the automatic creation of CRUD action methods and views is known as scaffolding).
You’ll soon have a fully functional web application that lets you create, list, edit, and delete movie entries.
If you run the app and click on the Mvc Movie link, you’ll get the following errors:
We’ll follow those instructions to get the database ready for our Movie app.
Warning
You must stop IIS Express before you update the database.
cd ..
to move back up to the project directorydotnet ef migrations add Initial
dotnet ef database update
标签:
原文地址:http://www.cnblogs.com/chucklu/p/5624265.html