From the course: Using Entity Framework Core with Legacy Databases

Setting up your project

From the course: Using Entity Framework Core with Legacy Databases

Start my 1-month free trial

Setting up your project

- [Instructor] Alright. We're finally ready to get our new application up and running against the database. We're going to use a .NET core console project, and add the entity framework core libraries to it. First, we need to install the .NET core SDK. We'll navigate to the Microsoft website for .NET core, and download the SDK. After downloading, we'll run the installation. Now the .NET core is installed, we can close this window, and close our browser. I'll use Windows key R and Command to open up a command window. Now, I'll create a new directory for my project. And navigate into it. Now that we're in the directory, we can use the .NET command line tools to create the project. First, with dotnet new console. This creates a simple project in the folder. Notice here that the dotnet restore command was automatically run as part of the project creation. This puts the dotnet packages in the folder we're executing the application from. Let's run the application with dotnet run. We see hello world, and the console application ran successfully. Now we could begin to add the entity framework core references to the project. The dotnet command line interface is one of a few ways to create projects and add packages as we're about to do. We could add the entity framework core packages from the nuget package manager in Visual Studio, the package manager console, or with dotnet core Power Shell commands. I'm using the dotnet CLI, because it's available on all the platforms that dotnet core is available, unlike Visual Studio and Power Shell. To add support for entity framework, we need two nuget packages. The first is for Sql Server. It automatically includes a reference to the EF core libraries. We'll add that package with dotnet, add package. Microsoft.EntityFrameworkCore.SqlServer. Now I'll clear the screen. With CLS. The next package that we wanna add allows us to scaffold models from an existing database. Dotnet add package. Microsoft.EntityFrameworkCore.Design. Let's build the application to see that it completes successfully. With dotnet build. Before we start scaffolding from our existing database, let's look at the new project in Visual Studio. I'm gonna type start dot, in the command window, to open up File Explorer in the current directory, and then double click on the project file to open the project. On the right hand side, we can drop down dependencies, and nuget, to see the packages that we've added. Now we can connect our project to our database.

Contents