© Eric Vogel 2021
E. VogelBeginning Entity Framework Core 5https://doi.org/10.1007/978-1-4842-6882-7_1

1. Installation

Eric Vogel1  
(1)
Okemos, MI, USA
 

In order to use Entity Framework Core 5, you will need some tools. These tools include Visual Studio (VS) 2019 and some NuGet packages for your solution.

Install Visual Studio

The first step is getting a version of Visual Studio 2019. The Community Edition of Visual Studio 2019 for Windows can be used for all code in this book. If you are running macOS, you can also opt to install Visual Studio for Mac. I’ll be using Windows for the remainder of the book, but the steps are about the same for macOS.

You can download Visual Studio 2019 from https://visualstudio.microsoft.com/downloads/ as seen in Figure 1-1.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig1_HTML.jpg
Figure 1-1

Download VS 2019

Next, install the latest Visual Studio 2019 and select the .NET Core option as seen in Figure 1-2.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig2_HTML.jpg
Figure 1-2

Install .NET Core Support

Entity Framework Core 5 will run on both .NET Core 3.1 and .NET 5. For this book, we will be using .NET Core 3.1.

Create a Project

Entity Framework Core 5 works on a variety of application types from console apps, desktop apps, and web apps. For this book, we will be creating an ASP.NET Core MVC (Model-View-Controller) app.

We will now create the project in Visual Studio and install all the required tools to use Entity Framework Core 5. First, create a new project in Visual Studio as seen in Figure 1-3.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig3_HTML.jpg
Figure 1-3

Create a New Visual Studio 2019 Project

Then create a new ASP.NET Core web application as seen in Figure 1-4.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig4_HTML.jpg
Figure 1-4

New ASP.NET Core Web App

Next, name your ASP.NET Core web application. I named my app EFCore5WebApp as seen in Figure 1-5.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig5_HTML.jpg
Figure 1-5

Naming the Web App

After that, select ASP.NET Core 3.1 as the target framework and select the Model-View-Controller template as seen in Figure 1-6.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig6_HTML.jpg
Figure 1-6

Creating an ASP.NET Core 5.0 MVC App

Then click the “Create” button to create the project and solution. After this, you will see the generated project opened in Visual Studio.

Install Entity Framework

Entity Framework Core 5 has providers for Microsoft SQL Server, SQLite, Cosmos, and in-memory databases. For this book, we will be using the SQL Server provider.

Entity Framework is installed through the NuGet Package Manager. We will be installing the Entity Framework Core 5 SQL Server NuGet package, which will allow us to interact with a Microsoft SQL Server instance.

Now it is time to install the Entity Framework Core 5 SQL Server NuGet package into the web app. Open the NuGet installer and search for “Entity Framework” and click the “Include prerelease” checkbox as shown in Figure 1-7.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig7_HTML.jpg
Figure 1-7

Install the EF Core 5 SQL Server NuGet Package

Click the Install button, and you should be prompted to confirm your installation as seen in Figure 1-8. Make sure the version is 5.* and that the package name is Microsoft.EntityFrameworkCore.SqlServer, which will install Entity Framework Core 5 with SQL Server support.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig8_HTML.jpg
Figure 1-8

Confirm EF Core SQL Server NuGet Installation

Lastly, you’ll be prompted to accept the license to install the EF Core 5 NuGet package as seen in Figure 1-9.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig9_HTML.jpg
Figure 1-9

Confirm EF Core 5 NuGet License

Click the I Accept button, and the package will be installed.

Install the Core Tools Package

Finally, you’ll need to install the Entity Framework 5 Core Tools package, which will allow you to create and update your database from the NuGet Package Manager Console. Open up the NuGet Package Manager and search for “Entity Framework Tools” and install the package as seen in Figure 1-10. Make sure to install the package named “Microsoft.EntityFrameworkCore.Tools” and that the version is 5.*.
../images/499766_1_En_1_Chapter/499766_1_En_1_Fig10_HTML.jpg
Figure 1-10

Install the EF Core 5 Tools NuGet Package

You have now successfully installed the needed tools to use Entity Framework Core 5. In the next chapter, we will cover how to move the Entity Framework 5 NuGet installation to a data access layer (DAL) project and how to structure your application using an N-tier architecture. You are well on your way to learning how to effectively use Entity Framework Core 5.

SQL Server Database

For this book, we will be using SQL Server Express LocalDb that is installed automatically by Visual Studio 2019 Preview as part of the .NET Core workload. Feel free to use your own full SQL Server instance. I will cover how to set the database connection string and create the database from code in Chapter 5.

Summary

In this chapter, you’ve installed the tools needed to use Entity Framework Core 5 with a Microsoft SQL Server instance. You’ve installed the latest Visual Studio 2019 and Entity Framework Core 5 into our solution.

With this groundwork lain, we can move on to structuring our application in the next chapter to effectively use Entity Framework Core 5. A good architecture goes a long way in allowing the application to be easily tested through unit and integration tests and eases maintenance of the application over time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.136.165