We may earn an affiliate commission when you visit our partners.
Course image
Mosh Hamedani

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.

Read more

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.

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

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- 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.

Enroll now

Here's a deal for you

We found an offer that may be relevant to this course.
Save money when you learn. All coupon codes, vouchers, and discounts are applied automatically unless otherwise noted.

What's inside

Learning objectives

  • 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
  • Show more
  • Show less

Syllabus

Introduction
About this Course
About Me
Asking Questions
Read more
Getting Started
What is Entity Framework?
Workflows
Demo: Database-First Workflow
Demo: Code-First Workflow
Database-First or Code-First?
Summary
Building a Model using Database-First Workflow

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.

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

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.

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

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


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

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.

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.

Exercises
Building a Model using Code-First Workflow

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.

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.

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.

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.

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.

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.

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.

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.

Seeding Database
Overriding Code-First Conventions

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.

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

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.

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

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.

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

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.

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.

Querying Data using LINQ

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.

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

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)

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)

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)

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.

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.

Loading Related Objects

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

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.

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.

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.

Updating Data

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

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

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

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.

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.

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.

Using Entity Framework in Your Applications

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.

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.

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.

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.

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.

Conclusion
Final Words
Coupon to My Other Courses

Good to know

Know what's good
, what to watch for
, and possible dealbreakers
Teaches core concepts of Entity Framework with clear and concise lectures
Builds a strong foundation for beginners in Entity Framework
Covers topics from database-first and code-first workflows to querying data with LINQ and handling related objects
Provides exercises from real-world scenarios to help learners prepare for challenges
Course is produced with Entity Framework 6, which may be a caveat for those using older versions

Save this course

Save Entity Framework in Depth: The Complete Guide to your list so you can find it easily later:
Save

Reviews summary

Excellent course for entity framework

According to students, this course is amazing and a great value. The teacher, Mosh, is considered the best programming teacher on the platform. Students say the course provides great tips and best practices for those who wish to work in the field professionally.
The course provides students with valuable information which can be applied in professional settings.
"amazing value"
"with great tips, best practices, which is very important if you are planning to be a professional"
The teacher is highly experienced.
"great teacher"
"Mosh is the best programming teacher on the platform period"

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Entity Framework in Depth: The Complete Guide with these activities:
Participate in online discussion forums for Entity Framework Core
Engage with other learners and experts by participating in online discussion forums dedicated to Entity Framework Core.
Browse courses on Entity Framework Core
Show steps
  • Join online discussion forums, such as Stack Overflow or Reddit
  • Ask questions and share your experiences
  • Help others by answering their questions
Follow Entity Framework Core tutorials
Reinforce your understanding of Entity Framework Core concepts by following guided tutorials and working through examples.
Browse courses on Entity Framework Core
Show steps
  • Find reputable tutorials on Entity Framework Core
  • Follow the tutorials step-by-step
  • Experiment with the code and try different scenarios
Practice LINQ queries
Improve your understanding of LINQ queries by practicing with various scenarios and exercises.
Browse courses on LINQ
Show steps
  • Set up a practice environment with Entity Framework Core
  • Write LINQ queries to retrieve data from a database
  • Use LINQ to filter, sort, and group data
One other activity
Expand to see all activities and additional details
Show all four activities
Build a data access layer using Entity Framework Core
Apply your knowledge of Entity Framework Core by building a data access layer for a real-world application.
Browse courses on Entity Framework Core
Show steps
  • Design the data model for your application
  • Create the Entity Framework Core DbContext
  • Implement CRUD operations (Create, Read, Update, Delete)
  • Test your data access layer thoroughly

Career center

Learners who complete Entity Framework in Depth: The Complete Guide will develop knowledge and skills that may be useful to these careers:
Software Architect
A Software Architect designs, builds, and maintains the overall software architecture of a system. This course can help lead to success in this career role by providing a deep understanding of the principles and practices of software development. The course covers topics such as object-oriented programming, database design, and software testing, which are all essential skills for a Software Architect. Additionally, the course provides hands-on experience with Entity Framework, a popular object-relational mapping (ORM) framework, which is often used in enterprise software development.
Database Administrator
A Database Administrator (DBA) is responsible for the day-to-day operation and maintenance of databases. This course can help lead to success in this career role by providing a deep understanding of relational database management systems, including database design, database optimization, and data recovery. The course also covers Entity Framework, an ORM framework that can be used to interact with databases from .NET applications.
Web Developer
A Web Developer designs, builds, and maintains websites and web applications. This course can help lead to success in this career role by providing a deep understanding of the principles and practices of web development. The course covers topics such as HTML, CSS, JavaScript, and ASP.NET MVC, which are all essential skills for a Web Developer. Additionally, the course provides hands-on experience with Entity Framework, an ORM framework that can be used to interact with databases from web applications.
Data Analyst
A Data Analyst collects, analyzes, and interprets data to help businesses make informed decisions. This course can help lead to success in this career role by providing a deep understanding of data analysis techniques, including data mining, data visualization, and statistical analysis. The course also covers Entity Framework, an ORM framework that can be used to access data from various sources, including databases and flat files.
Business Analyst
A Business Analyst gathers and analyzes business requirements to help businesses improve their processes and systems. This course can help lead to success in this career role by providing a deep understanding of business analysis techniques, including requirements gathering, process mapping, and cost-benefit analysis. The course also covers Entity Framework, an ORM framework that can be used to access data from various sources, including databases and spreadsheets.
Software Engineer
A Software Engineer designs, develops, and tests software applications. This course can help lead to success in this career role by providing a deep understanding of software development principles and practices. The course covers topics such as object-oriented programming, software design, and software testing, which are all essential skills for a Software Engineer. Additionally, the course provides hands-on experience with Entity Framework, an ORM framework that can be used to interact with databases from software applications.
Data Scientist
A Data Scientist uses data to solve business problems. This course can help lead to success in this career role by providing a deep understanding of data science techniques, including data mining, machine learning, and statistical analysis. The course also covers Entity Framework, an ORM framework that can be used to access data from various sources, including databases and flat files.
Information Technology Manager
An Information Technology Manager plans and manages the IT infrastructure of an organization. This course can help lead to success in this career role by providing a deep understanding of IT management principles and practices. The course covers topics such as IT strategy, IT governance, and IT security, which are all essential skills for an Information Technology Manager. Additionally, the course provides hands-on experience with Entity Framework, an ORM framework that can be used to access data from various sources, including databases and spreadsheets.
Computer Programmer
A Computer Programmer writes and maintains code for software applications. This course can help lead to success in this career role by providing a deep understanding of programming principles and practices. The course covers topics such as object-oriented programming, software design, and software testing, which are all essential skills for a Computer Programmer. Additionally, the course provides hands-on experience with Entity Framework, an ORM framework that can be used to interact with databases from software applications.
IT Consultant
An IT Consultant provides IT advice and services to businesses. This course can help lead to success in this career role by providing a deep understanding of IT principles and practices. The course covers topics such as IT strategy, IT governance, and IT security, which are all essential skills for an IT Consultant. Additionally, the course provides hands-on experience with Entity Framework, an ORM framework that can be used to access data from various sources, including databases and spreadsheets.
IT Project Manager
An IT Project Manager plans and manages IT projects. This course can help lead to success in this career role by providing a deep understanding of project management principles and practices. The course covers topics such as project planning, project execution, and project closure, which are all essential skills for an IT Project Manager. Additionally, the course provides hands-on experience with Entity Framework, an ORM framework that can be used to access data from various sources, including databases and spreadsheets.
IT Auditor
An IT Auditor evaluates the IT systems and processes of an organization. This course can help lead to success in this career role by providing a deep understanding of IT auditing principles and practices. The course covers topics such as IT risk management, IT compliance, and IT security, which are all essential skills for an IT Auditor. Additionally, the course provides hands-on experience with Entity Framework, an ORM framework that can be used to access data from various sources, including databases and spreadsheets.
IT Security Analyst
An IT Security Analyst protects the IT systems and data of an organization. This course can help lead to success in this career role by providing a deep understanding of IT security principles and practices. The course covers topics such as network security, data security, and cloud security, which are all essential skills for an IT Security Analyst. Additionally, the course provides hands-on experience with Entity Framework, an ORM framework that can be used to access data from various sources, including databases and spreadsheets.
IT Help Desk Technician
An IT Help Desk Technician provides technical support to users of an organization's IT systems. This course may be useful by providing a basic understanding of IT principles and practices. However, the course is not specifically tailored to the role of an IT Help Desk Technician.
IT Network Administrator
An IT Network Administrator manages the network infrastructure of an organization. This course may be useful by providing a basic understanding of network principles and practices. However, the course is not specifically tailored to the role of an IT Network Administrator.

Reading list

We've selected eight books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Entity Framework in Depth: The Complete Guide.
Classic in the software development community. It provides practical advice on how to write clean, maintainable code. It valuable resource for anyone who wants to improve their coding skills.
Is an excellent introduction to design patterns for those who are new to the concept. It uses a fun and engaging approach to explain different design patterns and how they can be used to improve software design.
C# In Depth, 4th Edition provides in-depth coverage of the C# language and valuable resource for those who want to gain a deeper understanding of the language. is particularly useful for those who are new to C# or who want to improve their programming skills.
This is an excellent reference book for database concepts. It is not specific to Entity Framework but it provides a solid foundation for understanding the underlying concepts of relational database management systems.
Provides a solid foundation for understanding domain-driven design, which valuable approach for designing complex software systems. While it is not specific to Entity Framework, it is still a recommended read for those who want to improve their software design skills.
Is an excellent overview of the C# programming language. While it does not focus on Entity Framework, it is still a valuable addition to a supplementary reading list as it provides needed context for understanding concepts used in the Entity Framework.
CLR via C# recommended supplemental text for those who want more depth on the .NET framework. While this book is an excellent overall resource, it actually does not discuss LINQ or Entity Framework, so it is only moderately useful in direct support of this course.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Here are nine courses similar to Entity Framework in Depth: The Complete Guide.
Entity Framework Core - A Full Tour
Most relevant
Entity Framework Core 2: Getting Started
Most relevant
Entity Framework 6 in the Enterprise
Most relevant
Integration Testing of Entity Framework 6 Applications
Most relevant
ASP.NET Core Web API Fundamentals
Most relevant
EF Core 6 Fundamentals
Building a Data-driven ASP.NET Core 6 Blazor Server...
Building an Enterprise App with WPF, MVVM, and Entity...
Data Access in C# Fundamentals
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2024 OpenCourser