First, create a new class under the models directory (preferably with the same name as the new data table below)
Writing mapped fields and database connection classes
namespacemyfristasp.models{ Public classMovie { Public intID {Get;Set; } Public stringTitle {Get;Set; } PublicDateTime ReleaseDate {Get;Set; } Public stringGenre {Get;Set; } Public decimalPrice {Get;Set; } } Public classMoviedbcontext:dbcontext { PublicDbset<movie> Movies {Get;Set; } }}
Ii. Adding a connection string to a configuration file (Web. config)
<name= "Moviedbcontext" connectionString= "Data source= (LocalDb) \ MSSQLLOCALDB; attachdbfilename=| datadirectory|\movices.mdf;integrated security=true "
ProviderName = "System.Data.SqlClient" />
Third, add a new controller under the Controller directory, select ' Include View MVC5 controller (using Entity Framework) '
Four, this step may be error
Popup "Error running Selected code generator" window;
Solve:
In the tools->nuget Package Manager, Package Manager console, enter commands install-package entityframework.sqlservercompact-version 6.1.3
Download the package and rebuild the solution;
Five, after the completion of the error after the new controller, the inside of the code has been automatically generated, you can test the run;
ASP. NET MVC adds model and connects to local database