Get started with Entity Framework Core

Download the code example for our Get Started with EF Core course.

The course begins with creating a DbContext into an ASP.NET Core Web API. The DbContext allows the Web API to communicate with the SQL Server database.

C# coding challenges

C# coding challenges

Our online code editor allows you to compile the answer.

So we can support continuous integration and deployment, we then focus on how to add migrations and update the database.

The next stages focus on CRUD operations. The code features the ability to create, read, update or delete an entity from a database using the Web API.

Joining data is one of the fundamental skills you need to know. The code features examples on how to use the Include method to join two tables together.

Finally, we round it off with using Entity Framework to query using raw SQL queries and stored procedures.

Software

This is the software that will need to be installed onto your machine.

Install LocalDB

Make sure that you have LocalDB installed on your machine. You can check in Visual Studio by going to Tools and Get Tools and Features....

This will load up the Visual Studio Installer. If you go to the Individual components tab and do a search for LocalDB.

If SQL Server Express LocalDB is ticked, it is already installed. If it's not, just enable it and follow the instructions to install it.

Install LocalDB through the Visual Studio Installer

Install LocalDB through the Visual Studio Installer

Get the application working

Download the code example

Fill out the code example form. We will send you an email where you can download the code example.

Importing the database

The database can be found in the Database folder as part of the code example.

In SQL Server Management Studio, connect to LocalDB by selecting the Server name as (localdb)\MSSQLLocalDB and the Authentication as Windows Authentication.

Login to LocalDB in SQL Server Management Studio

Login to LocalDB in SQL Server Management Studio

Right-click on the Databases folder and go to Import Data-tier Application.

In the Import Settings tab, select Import from local disk and find RoundTheCodeEFCore.bacpac which is included in the Database folder of the code example.

Import the database using SQL Server Management Studio

Import the database using SQL Server Management Studio

In the Database settings tab, ensure that the New database name is set as RoundTheCodeEFCore.

Set the database name when importing a bacpac database.

Set the database name when importing a bacpac database.

You should be able to continue through the next steps with the options untouched and it should successfully import the database.

Open the project in Visual Studio

Open up RoundTheCode.EFCore.sln in Visual Studio 2022.

Start the project in Visual Studio. It will load up https://localhost:7110/swagger/index.html.

You can test out each of the endpoints and see what response is returned.

More information

You are downloading the code example for the whole of the course.

Remember to check out each of the six-parts in our Get Started with EF Core course to understand how the code example works.