
Map your .NET app to databases with energy framework, keep models in sync with migrations, and build API projects using entity framework, data annotations, fluent API, repository layer, and LINQ.
Introduces his twenty-year tech career, from early programming to an electrical engineering master's and MBA, highlighting work with NASA and the US Navy and using energy framework to build applications.
Follow along with the instructor and complete exercises to maximize learning, since environments may differ. When stuck, search Google or Stack Overflow and ask questions within seven days for help.
Understand why you would use Entity Framework in your application
What you need to have set up before you start working with Entity Framework
Create a web application using Entity Framework
Create your first database context
Configure your entity framework core by wiring the db context to a sql server provider using the default connection from appsettings.json for local databases.
Apply and manage database migrations with Entity Framework Core, ensuring configuration control and safe changes, while using data annotations for field validation and date formatting.
Apply a migration to modify an existing table by making the expense date time field nullable, then update the database and verify changes in SQL Server Object Explorer.
Explore data annotations to control database schemas, marking primary keys with key, enforcing required fields, and constraining max and min lengths, then apply migrations.
Add a second model for the expense line, override table and column names, set decimal precision, update the DbContext, and generate migrations to create the expense details table.
Sometimes you do not want to write a property to the database as a database field. Use the NotMapped database annotation for that.
Learn how to use database migrations to apply your C# models to the database with configuration control, keep them in sync with your app, and validate data with navigation properties.
Navigation properties are what we use to link two classes together. These navigation properties will also help link our databases together using a concept of foreign keys.
Define dependent and principal entities in a one-to-many relationship using foreign keys and principal keys to link expense header and expense line. Explain navigation properties—collection, reference, and inverse—for mapping data.
In this lesson we will learn how to remove a navigation property we have already applied to our database.
Master the fluent API in Entity Framework Core to configure and modify database properties through method chaining, achieving granular control beyond data annotations.
Use the fluent API in on model creating to define a computed total cost for expense lines as quantity multiplied by unit cost in the database.
Learn to use the fluent api on the database context to create a computed string column that concatenates first name and last name into full name, via migration and update.
Configure a USD exchange rate field on the expense header with decimal precision of 13.4 using the fluent API, enforce non-nullability, and apply a migration to update the database.
Move each entity configuration into its own file to enforce the single responsibility principle, apply configurations in the context with a builder, and maintain separation of concerns for EF Core.
Move entity configurations to separate files and auto-apply them from the assembly with modelBuilder.ApplyConfigurationsFromAssembly, using reflection to load all IEntityTypeConfiguration implementations for maintainable, separated concerns.
Explore how to retrieve all users from a database table using Entity Framework Core, returning a list via a controller and a REST API in JSON.
Learn to add a new user to the database using a post method, EF Core context add, and save changes to return the created user with a generated ID.
Update data with a put request, validate IDs, track entity changes, and save updates returning no content; test with Postman while preserving created and last modified dates.
Implement a repository layer to decouple data access from the persistence framework, eliminating duplicated queries. Use a unit of work to coordinate saves across multiple in-memory collections.
Create a generic repository interface using IRepository<T> with GetAll, GetById, Add, AddRange, Remove, and RemoveRange, returning IEnumerable<T> to enable decoupled data access.
Create a generic repository implementation using a DbContext, exposing get all, get by id, add, add range, remove, and remove range, to decouple data access from a specific context.
Extend the generic repository to build a user repository and implement its contract. Wire it to the application DB context and add a get by first name method.
Learn to implement the unit of work pattern by defining a disposable IUnitOfWork interface, exposing repository contracts, and building a concrete unit of work that coordinates context saves and repositories.
Configure dependency injection to map the unit of work interface to its implementation and use it to access data via the repository pattern, abstracting the context.
Expand a repository in the complete guide to entity framework core by using robust LINQ queries with lambda expressions to filter by first name and apply order by descending.
Use LINQ to fetch a single record from the database, using first, first or default, or single methods in a user repository, by first name or id.
Explore how to expand queries in a repository using any, count, and min/max operations in Entity Framework Core, including counting by first name and retrieving max and min user IDs.
Learn how to write a quick LINQ select query with lambda expressions to return a subset of data, such as the first names from the users table, via IEnumerable results.
Apply a code-first approach with migrations to map your model to any database, not SQL Server. Leverage fluent API, data annotations, repository layer, and LINQ for robust querying and optimization.
This course is a complete guide to Entity Framework Core. Whether your are a beginner or more advanced this course is for you. In this course you will learn the following.
Use a code first approach to create a database model
Apply migrations to your database to apply your code model to your database
Configure your database using data annotations and a fluent API
Work with LINQ to perform database queries
Create a repository layer to manage your queries in code
Add, update and delete your database objects