Entity Framework in Depth: The Complete Guide
4.7 (2,145 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
8,987 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Entity Framework in Depth: The Complete Guide to your Wishlist.

Add to Wishlist

Entity Framework in Depth: The Complete Guide

Connect your applications to a SQL Server database
Bestselling
4.7 (2,145 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
8,987 students enrolled
Created by Mosh Hamedani
Last updated 5/2017
English
English
Current price: $10 Original price: $100 Discount: 90% off
5 hours left at this price!
30-Day Money-Back Guarantee
Includes:
  • 6.5 hours on-demand video
  • 1 Article
  • 7 Supplemental Resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Understand the differences between database-first and code-first workflows
  • Build a domain model using database-first workflow
  • Build a domain model using code-first workflow (with an existing or a new database)
  • Use code-first migrations to upgrade or downgrade your database
  • Override code-first conventions (using data annotations and fluent API)
  • Query data using LINQ (using query syntax and extension methods)
  • Use eager loading, lazy loading and explicit loading effectively
  • Add, update and remove objects
  • Use additional tools to profile and troubleshoot your applications
  • Understand what the repository pattern is, what and if you need it, and how to implement it
  • Apply best practices with Entity Framework
View Curriculum
Requirements
  • Good understanding of advanced C# constructs (generics, lambda expressions)
Description

With over 6,500 students and 1,500+ positive reviews, this course is Udemy's most popular course for learning Entity Framework! 


Entity Framework is an Object / Relational Mapper (O/RM) that helps you read and write data from and to a database. In this course, Mosh, teaches you the core concepts of Entity Framework through a series of clear, concise and hands-on lectures.


Whether you're new to Entity Framework, or been using it for a while but are looking for a comprehensive course with a clean structure to fill the missing parts, you're going to love this course.


By the end of watching this course, you'll be able to:

  • Understand the differences between code-first and database-first workflows
  • Build a domain model using database-first workflow
  • Build a domain model using code-first workflow (with a new or an existing database)
  • Use code-first migrations to upgrade or downgrade your database
  • Override code-first conventions (using data annotations and fluent API)
  • Query data using LINQ (using query syntax and extension methods)
  • Use eager loading, lazy loading and explicit loading effectively
  • Add, update and remove objects
  • Use additional tools to profile and troubleshoot your applications
  • Understand what the repository pattern is, why and when to use it and how
  • Apply best practices with Entity Framework


Unlike other books or courses that teach Entity Framework like a manual, Mosh walks you through real-world scenarios using his extensive experience in the field. Not only does he teach you the fundamentals of Entity Framework, he'll also teach you best practices along the way.


In each section, you'll find exercises to help you reinforce the materials. These exercises have been chosen from real-world scenarios to help you prepare for the challenges of the real-world. Also, some sections include cheat sheets so you can quickly review what you learn in that section.


This course is produced with Entity Framework 6. If you're using an older version of Entity Framework, you can still take this course as long as your version of Entity Framework is 4.1 or higher.



PREREQUISITES

In order to take this course, you should have at least 3 months experience programming in C#. If you need to strengthen your C# fundamentals, you can take Mosh's related courses:

  • C# Basics for Beginners
  • C# Intermediate: Classes, Interfaces and Object-oriented Programming
  • C# Advanced 



WHAT OTHER STUDENTS WHO HAVE TAKEN THIS COURSE SAY:

"May God bless you and your efforts to create high quality courses. This has really changed my life from working as a security guard and doing websites for free, now I am a professional." -Danish Jafri


"I'm impressed by Mosh's ability to strike the right balance of topic background, demo and tip and tricks to get around common issues when learning a technology. Great job Mosh! I'm more than happy to have invested my time and money in your work." -Ben Holtzman


"Excellent course! Mosh has a brilliant style and all of his courses are well presented and very high quality. This course was no exception and I learnt a lot from it." -Steven Barnett


"It´s a pleasure following the lessons, It´s like a good book, you always want to read another chapter. This is not siimple a course of EF, it goes further, gives a very good explanation of Linq and the most brilliant description of Repository Pattern and Unity of work. Please keep doing courses. To be honest I believe that you should leave your work and spend the rest of your life teaching ;)." -Martin Suarez


"I'd taken a lot of video classes, and this is the best I'd taken. Very well explained, detailed and a good real life examples, lots of tips and more." -Oscar Vargas


"As always... Mosh nails it with his thorough explanations (without all the "I'm better than you vibe")." -Mike Loffland



100% MONEY-BACK GAUARANTEE

This course comes with a 30-day money back guarantee. If you're not happy, ask for a refund, all your money back, no questions asked.



Do you want to take your programming skills to the next level?

Join the other 6,500 happy students who have taken this course and start coding within minutes.

Who is the target audience?
  • Any .NET developer who wants to persist or query domain objects from a database
Students Who Viewed This Course Also Viewed
Curriculum For This Course
79 Lectures
06:37:13
+
Introduction
3 Lectures 05:33


Asking Questions
02:58
+
Getting Started
7 Lectures 26:40




Demo: Code-First Workflow
09:07

Database-First or Code-First?
03:41

Summary
00:24
+
Building a Model using Database-First Workflow
11 Lectures 52:42
Introduction
00:35

In this lecture, we'll create a database using a SQL script. This database will be used throughout this section to build a model using database-first workflow.

This lecture contains downloadable script in the Supplementary Materials section.

Setting up the Database
00:54

In this lecture, you'll learn some handy features of the EDMX designer that make it easy for you to work with large, complex models. You'll learn how to:

  • Zoom in and out of your model
  • Export a diagram as image
  • Collapse or expand all entities
  • Move entities around, or have them automatically laid out in a clean way
  • Show or hide data type of properties
  • Rename entities and their members
A Quick Tour of EDMX Designer
06:46

In this lecture, you'll see the XML behind an EDMX model. I'll show you the conceptual model, storage model, and the mapping between the two, both in the XML and Model Browser.

You'll also learn how to modify the mapping between the storage model and the conceptual model.

Uncovering the EDMX
06:56

In this lecture, I'll deconstruct the connection strings with database-first models and explain what CSDL, SSDL and MSL resources mean.

Connection Strings
03:16

In this lecture, I'll take you through a few different scenarios when you modify your database. I'll show you how to keep your model in sync with the database when you:

  • Add a new table
  • Modify an existing table (including renaming columns, changing their data types, adding / removing columns)
  • Delete a table


Dealing with Database Changes
13:30

In this lecture, you'll learn how to import stored procedures and functions into your entity data model.

Importing Stored Procedures
05:28

In this lecture, we'll take a closer look at the Function Import dialog box. You'll learn how to deal with legacy databases with poorly named functions / stored procedures and prevent such pollutions to affect your model. I'll also introduce you to complex types, what they are, when they are useful, and how to create them.

Function Imports
07:38

In this lecture, you're going to learn how to use enums in your entity data model to improve the readability and maintainability of your code. I'll teach you how to define new enums in your model, or reference an existing enum in your project.

Working with Enums
07:22

Exercises
3 pages

Summary
00:17
+
Building a Model using Code-First Workflow
12 Lectures 01:03:01
Introduction
00:23

In this lecture, you'll learn how to build a more complex model (with a few classes and different types of associations between them) using the code-first workflow. More specifically, you'll see one-to-many and many-to-many relationships.

Code First with a New Database
13:15

A common misconception about the code-first workflow is that it is only suitable for greenfield projects without an existing database. In this lecture, I'm going to show you how to use the code-first workflow against an existing database.

Code First with an Existing Database
06:58

In this lecture, I'm going to show you a common issue that many beginners face when enabling migrations on an existing database. I'll introduce you to -IgnoreChanges and -Force switches of Add-Migration command and how they help you create the initial migration against an existing database.

Migrations: Enabling Migrations
04:21

In this lecture, you'll learn one migration scenario: adding a new class to your model and bringing your database in sync with your model. I'll also teach you how to populate the corresponding table using code. This is useful in scenarios where your tables have reference data that need to be automatically populated as part of running migrations.

Migrations: Adding a New Class
09:29

In this lecture, I'll walk you three modification scenarios:

  • Adding a new property to a class
  • Modifying an existing property
  • Deleting an existing property
Then, I'll show you how sometimes migrations can cause data loss and how to prevent this.
Migrations: Modifying an Existing Class
08:25

In this lecture, you'll learn how to bring your database in sync with your model when you delete an existing class. I'll also teach you how to preserve data in your database for historical reasons.

Migrations: Deleting an Existing Class
05:53

What if one of your past migrations was a mistake? What if you shouldn't have made that change on your model? This is a scenario that happens occasionally in the real-world and many beginners don't know how to deal with these situations. In this lecture, I'll explain how to recover from your mistakes in a safe way.

Migrations: Recovering from Mistakes
01:22

There are times that you need to restore your model and database to a previous state, perhaps for maintaining an older version of your application. In this lecture, I'll present you with two strategies for doing this.

Migrations: Downgrading a Database
06:01

Seeding Database
06:27

Exercises
2 pages

Summary
00:27
+
Overriding Code-First Conventions
11 Lectures 01:03:37
Introduction
00:25

In this lecture, I'll introduce you to two ways to override code-first conventions: Data Annotations and Fluent API. I'll show you an example of each approach, and then compare them side-by-side.

Overriding Conventions
08:17

In this lecture, we'll have a closer look at various data annotations to override code-first conventions. You'll learn how to override:

  • The name of tables and their schema
  • The name of columns and their type
  • Primary keys (including composite keys)
  • Null values
  • Length of strings
  • Foreign keys
  • Indices
Data Annotations
07:17

In this lecture, you'll put what you learned in the last lecture in action. We'll apply a few data annotations on our model and see the effect of these annotations in the database. This lecture contains downloadable project, so you can follow along with me.

Demo: Data Annotations
08:04

In this lecture, you'll learn how to use Fluent API to override:

  • Table names and their schemas
  • Primary keys (including composite keys)
  • Identity columns
  • Column types
  • Column types
  • Order of columns
  • Null columns
  • Length of strings
Fluent API: Basics
03:45

Here, I'll show you how to configure various kinds of relationships with Fluent API:

  • One-to-many
  • Many-to-many
  • One-to-zero/one
  • One-to-one

You'll also learn about Principal and Dependent in Entity Framework.

Fluent API: Relationships
10:05

In this lecture, you'll put what you've learned about Fluent API in action. This lecture includes downloadable code so you can code along with me. We'll use Fluent API to:

  • Make columns NOT NULL
  • Set a length to string columns
  • Change the name of foreign keys
  • Turn off cascade delete on relationships
Demo: Fluent API
13:28

In this lecture, you'll learn how to use Fluent API to override the name of foreign key columns in an intermediary table in a many-to-many relationship.

Demo: Fluent API (Advanced Configurations)
04:03

As you work with larger and more complex models, organising your Fluent API configurations becomes more important. In this lecture, I'll share with you my personal convention to organize your Fluent API configurations, which will incredibly simplify the maintenance of data access layer of your application.

Organizing Fluent API Configurations
07:37

Exercises
3 pages

Summary
00:36
+
Querying Data using LINQ
10 Lectures 01:05:44
Introduction
00:18

Here, I'll give you a brief background about LINQ. I'll explain what we had to do before LINQ and how LINQ makes our job much easier.

Introduction to LINQ
03:19

In this lecture, I'll show you how to use LINQ to get data out of a database. You'll get familiar with two ways to use LINQ:

  • Using LINQ syntax
  • Using LINQ extension methods
LINQ in Action
07:49

In this lecture, we'll have a closer look at the LINQ syntax. You'll learn how to:

  • Filter data
  • Sort data
  • Project data (into other types or anonymous types)
  • Group records
  • Use joins (inner join, group join and cross join)
LINQ Syntax
17:00

In this lecture, I'll teach you how to use LINQ extension methods to:

  • Filter data
  • Sort data (including multiple columns)
  • Project data (using Select and SelectMany)
  • Group records (using GroupBy)
  • Join records (e.g. inner join, group join and cross join)
LINQ Extension Methods
16:09

In this video, you'll learn the additional LINQ extension methods that are not available in LINQ syntax. You'll learn how to:

  • Partition data (e.g. returning records for a given page)
  • Return unique records
  • Use aggregate functions (e.g. Count, Max, Min, Sum)
  • Check to see if all records match a given criteria
  • Check to see if there are any records that match a given criteria
  • Return single records (e.g. First, Last, Single, etc)
LINQ Extension Methods: Additional Methods
05:41

In this lecture, you'll learn about deferred execution and its benefits. I'll also show you how to break this behaviour and immediately execute your queries, which is sometimes useful if your query expressions cannot be translated into SQL. I'll also introduce you to SQL Server Profiler for inspecting queries run on a database.

Deferred Execution
07:11

In this lecture, we'll dig deep into the IQueryable interface. I'll explain what it is and how it is different from IEnumerable. I'll also you introduce you to the differences between Func<> and Expression<> and how the latter allows extending queries.

IQueryable Explained
07:40

Exercises
3 pages

Summary
00:37
+
Loading Related Objects
7 Lectures 26:56
Introduction
00:14

In this lecture, you'll learn what lazy loading is, how it works under the hood and when to use / avoid it.

Lazy Loading
08:05

In this lecture, I'll introduce you to N + 1 problem that sometimes comes in technical interviews. I'll show you how lazy loading, if misused, can have an adverse impact on the performance of your application by causing unnecessary round-trips to the database.

N + 1 Problem
02:59

In this lecture, you'll learn what eager loading is and how to use it. I'll introduce you to the Include() method and show you two ways of using it: the poor way, and the good way.

Eager Loading
06:00

In this lecture, you'll learn how to use explicit loading to simplify complex queries that are result of too much eager loading. You'll also learn about another benefit of explicit loading: being able to apply filters when loading related objects.

Explicit Loading
08:55

Exercises
1 page

Summary
00:43
+
Updating Data
9 Lectures 32:37
Introduction
00:29

In this lecture, I'll show you what happens inside DbContext as we add, modify and remove objects.

Overview of Changing Data
01:23

In this lecture, you'll learn how to add objects using Entity Framework. I'll show you three ways to create association between your objects and explain which approach works better in WPF or ASP.NET MVC applications:

  • Using an existing object in a context
  • Using foreign key properties
  • Using the Attach method
Adding objects
07:49

In this lecture, you'll learn how to update objects with Entity Framework.

Updating objects
02:22

In this lecture, you'll learn how to remove one or a range of objects from your database. I'll show you two examples, one with CASCADE DELETE enabled, and another without it.

Removing objects
06:44

In this lecture, I'll show you how to get the state of your objects from DbContext. This can be useful when troubleshooting your applications and you want to know exactly what is happening inside a DbContext. Also, if you want to implement an audit trail, you can get these of these objects and dump them into an audit trail.

Working with Change Tracker
06:03

In this lecture, I'll introduce you to a very useful tool when working with LINQ and Entity Framework: LINQPad. I'll give you a quick tour of LINQPad and how easily you can run your queries to get immediate feedback about the return values and SQL statements executed on the database.

LINQPad
07:27

Exercises
1 page

Summary
00:20
+
Using Entity Framework in Your Applications
7 Lectures 45:56
Introduction
00:33

In this lecture, I'll explain what repository pattern is and what it is not, its benefits, why and if you need, and address some of the misconceptions about repositories. Some developers argue that the repository pattern is already implemented in Entity Framework and there is no need to re-implement it. I'll explain why this argument is not correct with real-world examples.

Repository Pattern
11:42

In this lecture, I'll walk you step-by-step through implementing the repository and unit of work patterns with Entity Framework. I'll show you the interfaces and their implementation. You can download the solution in the Supplementary Materials of this lecture.

Implementing the Repository Pattern
14:35

In this lecture, I'll give you a recipe to structure your applications. I'll show what classes go in each layer. You can download the solution in the Supplementary Materials of this lecture.

Structuring Your Applications
04:09

In this lecture, you'll see an example of Entity Framework in an ASP.NET MVC application. I'll show you how to display the list of courses on the home page and add a new course to the database. You'll learn two ways to work with contexts: the simple way by directly initialising a private field in the constructor, and a more advanced way, using dependency injection.

ASP.NET MVC Example
07:42

In this lecture, you'll see an example of Entity Framework in a WPF application. I'll show you how to bind a data grid to a list of courses and add a new course to the list.

WPF Example
06:14

Summary
01:01
+
Conclusion
2 Lectures 01:35
Final Words
01:01

Get My Other Courses with a Discount
00:34
About the Instructor
Mosh Hamedani
4.6 Average rating
39,095 Reviews
121,571 Students
16 Courses
Passionate Software Engineer and Best-selling Author

Mosh (Moshfegh) Hamedani is a passionate and creative software engineer with a strong focus on pragmatism and simplicity. He started programming at the age of seven on a Commodore 64. Later, during his high school years, he started learning C and C++ . In 2002, along with the first release of .NET, he shifted his focus to C#. Since then, he has been involved in the design and implementation of numerous software projects, including modern web applications, mobile apps, desktop applications and frameworks.


He started teaching on Udemy in 2014 and currently he has over 100,000 students in 182 countries. He's the author of several best-selling courses on Udemy and #1 ranking course on Pluralsight (Become a Full-stack .NET Developer). 


Mosh has a Master of Science in Network Systems and a Bachelor of Science in Software Engineering. He is also a Microsoft Certified Application Developer, Technology Specialist (Web Applications) and Professional.


Outside the software world, Mosh is a photographer, a pianist and a passionate Latin dancer.