
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.
Set up the tools and environment for the framework, create the first plain old class object, establish a database context, map DbSet properties, and configure the connection for migrations.
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 Entity Framework Core migrations with a code-first approach, add an initial migration, and run update-database from package manager console, reviewing up and down methods that create expense headers table.
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.
Create custom error messages for validation using data annotations, leveraging the {0} placeholder to display property names, and apply messages for required and maximum length constraints in web forms.
Learn to undo an empty migration in Entity Framework Core with the package manager console, removing the migration and updating the model snapshot to keep the context in sync.
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.
Learn how to apply the range data annotation in Entity Framework Core to enforce min and max values for unit cost and quantity, with custom error messages.
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.
Connect multiple entity models in entity framework core using navigation properties, covering one-to-many and many-to-many relationships among headers, lines, expenses, and users.
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.
Link multiple navigation properties to connect a single user to expenses as requester and approver, using explicit foreign keys and inverse properties in EF Core.
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.
Learn to configure a one-to-many relationship using the fluent API in Entity Framework Core, and see how it compares to data annotations in a single, cohesive setup.
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.
Use the fluent API to add created date and last modified date with value generation on add and on add or update, defaulting to the UTC date via a migration.
Create a rest api controller to perform crud operations on user data, using dependency injection to inject the application database context via a constructor and access the database.
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 fetch a single user by ID using EF Core, by finding it with the primary key and returning one user via api/user/{id}, with basic error handling.
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.
Learn how to delete a user with entity framework core by locating the user id, validating existence, removing it from the context, and saving changes for a no content response.
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.
Create application specific repository interfaces for each class and program against interfaces, not implementations. Provide a generic repository and a concrete user repository with a get by first name method.
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