First create the solution Dotnetcrazy
First, create the project
1. Select the. Net core to select the ASP. WEB Application Name Call Corecrazy
Here we select the Web application (Model View controller) to the left of the ASP. NET Core MVC haha that's what I'm going to do with EF. Take a step-by-step look down
Project creation completed as follows
Ii. managing NuGet Packages
Let's look at the Web application NuGet package First
This includes the Netcore app package provided by Microsoft
The database I'm using here is SqlServer2012 how to add EF dependencies?
Here we can enter the following command to add a dependency
NuGet Add dependency of EF
Input command: Install-package Microsoft.EntityFrameworkCore.SqlServer
A friend here will ask how the Package Manager console opens.
There are several places that can be opened.
And here it is.
Can be opened
Now let's enter the command
We're looking at what's changed under the project.
Next we generate the model from the database
Of course, the orders come fast.
Still in Package Manager console
Scaffold-dbcontext "Server=desktop-hm1rhjv\sqlexpress;database=dotnetcrazy; Trusted_connection=true; " Microsoft.entityframeworkcore.sqlserver-outputdir Models
Execution is complete and you will find
Is it déjà vu, bright?
We also configure Startup.cs to add Dependency injection
This is the default and we need to modify
Revision changed to
OK, okay, let's try. How to successfully access the database for read and write
Third, create the controller
Here we choose to not bother to write the test for success
The controller has been created here, and the view is also created at the same time because I'm too lazy to take the ready-made (*^__^*) hehe
Let's change the route.
Run up and look at the effect
Well, the effect came. Successfully accessing database data
New test
O (∩_∩) o haha
Feel can continue to learn Dotnetcore beginners do not spray
DotNet core Beginner to create the first Dotnetcore project