In this tutorial you will learn how to install Entity Framework Core on your project.
First create a new ASP.NET Core Web Application in Visual Studio 2017.
Next select .NET Core & ASP.NET Core 2.0 from the options.
For the project template select Web Application (Model-View-Controller), and click the OK button.
Now you are ready to Install Entity Framework Core on your application.
There are 2 things to install here:
EF Core has DB providers of all major databases. The installation of each of them is done through NuGet. Here I will tell you how to install DB provider for SQL Server database.
In your Visual Studio go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution, this will open the NuGet UI.
Here click the Browse link and search for Microsoft.EntityFrameworkCore.SqlServer on the text box.
It will show up on the results below the search box. Click on it, then on the right side check the checkbox given against the project.
Finally click the Install button.
The installation will start and you will see Preview Changes window. Click the OK button.
Next you will see the License Acceptance window, click the I Accept button.
Within few seconds the installation procedure will complete and the Microsoft.EntityFrameworkCore.SqlServer provider will be installed on your project.
You can verify it by seeing the Dependencies > NuGet section of your Solution Explorer.
There are many EF Core commands like Migration, scaffoldings that needs to be executed. We use 2 tools to execute them. These are:
Go to NuGet UI and search for Microsoft.EntityFrameworkCore.Tools, and install it (i.e the first one).
Installation of dotnet CLI is done in a different manner. Right click on the Project in the solution explorer and select Edit ‘YourSolution.csproj’.
The project file will open on the editor. You have to add the below lines to it.
<ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" /> </ItemGroup>
This will install the dotnet CLI.
Now open the package manager console (Tools > NuGet Package Manager > Package Manager Console) and enter dotnet ef command.
PM> dotnet ef
You will see a horse picture telling the dotnet CLI has been installed successfully.