DotNet core Beginner to create the first Dotnetcore project

Source: Internet
Author: User
Tags dotnet

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.