- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Core Tech
Guided: Getting Started with EF Core 10
In this Code Lab, you will build a complete data access layer for a .NET 10 application from the ground up. You will gain hands-on experience with Entity Framework Core 10 by configuring a database context, modeling entities, and implementing a full suite of Create, Read, Update, and Delete (CRUD) operations. By the end, you'll have a robust, testable service ready to manage data for any application, using SQLite for a lightweight, serverless database solution.
Lab Info
Table of Contents
-
Challenge
Introduction
Welcome to this Code Lab on building a data access layer with EF Core 10! In this lab, you'll create the core components needed to connect a .NET application to a database. You will define data models, configure a database context, and implement a service to handle all Create, Read, Update, and Delete (CRUD) operations.
Use SQLite as your database. SQLite is a lightweight, serverless database engine, so you can focus on EF Core concepts without the overhead of setting up a traditional database server.
info> If you get stuck, you can find solution files for each task in the
solutionfolder of your filetree.This lab experience was developed by the Pluralsight team using Forge, an internally developed AI tool utilizing Gemini technology. All sections were verified by human experts for accuracy prior to publication. For issue reporting, please contact us.
-
Challenge
Step 2: Project Setup and Modeling
Before you can work with data, you need to set up your project with the right tools and define the structure of your data. This involves adding the required EF Core libraries to your project and creating a C# class, known as an 'entity,' to represent a contact in your database.
-
Challenge
Step 3: Creating the DbContext
The
DbContextis a central class in EF Core. It acts as a bridge between your entity classes and the database. In this step, you will create your ownDbContextand tell it which entities it should manage. -
Challenge
Step 4: Implementing Create and Read Operations
Now that your models and context are defined, it's time to bring them to life. First, register your
DbContextandContactServicewith the application's service container. This is a key pattern in modern .NET called Dependency Injection. Then, implement the 'C' (Create) and 'R' (Read) parts of CRUD, allowing you to add new contacts and retrieve them. -
Challenge
Step 5: Implementing Update, Delete, and Querying
In this final step, you'll complete the data service by implementing the remaining CRUD operations: Update and Delete. You will also write a more advanced query to search for contacts by name, demonstrating the power and flexibility of LINQ with EF Core.
-
Challenge
Step 6: Verify Your API from the Command Line
In this step, you'll run a command-line smoke test that starts your API in the background and exercises it with real HTTP requests. This gives you an end-to-end verification that your application runs, routes correctly, and performs database operations successfully.
- Open
scripts/api-smoke-test.shand review what it does (start the API, wait for readiness, run Create/Read/Update/Search/Delete requests, then shut the API down). - Run the script:
bash scripts/api-smoke-test.shIf the script fails, it prints the HTTP call that failed and the API output log to help you diagnose the problem. Congratulations on completing the lab! You set up EF Core with SQLite, modeled an entity, created a
DbContext, configured dependency injection, and implemented a full CRUD service with a searchable query—then validated everything end-to-end by running a live API smoke test from the command line. - Open
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.