What is Entity Framework?4:19 with James Churchill
Let's take a moment to talk about databases and the .NET Framework's support for working with databases. We'll also take a look at what Entity Framework is and how it offers developers a better way of working with data in their applications.
In the video, I referred to POCOs as "Plain Old C# Objects", though they're sometimes known as "Plain Old CLR Objects". The CLR is the part of the .NET Framework that manages the execution of .NET applications. Click here for more information about the .NET CLR.
Entity Framework Data Providers
While EF is typically used with SQL Server, other databases are supported through the use of data providers. Here are links to some common alternatives.
If you'd like to learn more about databases, see these Treehouse courses.
For more information about LINQ, see this Treehouse course.
LINQ to Entities enables developers to write EF queries using C#. For more information see:
EF Development History
EF has improved greatly since its early releases. Here's an overview of the development history of EF.
- Initially only supported Database First workflow
- No support for POCO entity classes
- Model First workflow
- Support for POCO entity classes
- Lazy loading
- First version shipped outside of the .NET Framework
- Added support for Code First workflow
- Introduced Code First Migrations
- EF is open sourced
- Enum support
- EF Power Tools
- Async query and save
- No longer dependent on the .NET Framework
- Full list of changes at https://msdn.microsoft.com/en-us/data/jj574253.aspx
Before we start building out our updated comic book data model, 0:00 let's take a moment to talk about databases and 0:04 the .NET framework support for working with databases. 0:06 We'll also take a look at what Entity framework is and 0:10 how it offers developers a better way of working with data in their applications. 0:12 There are many different kinds of databases. 0:18 Databases that store data in tables, such as MySQL or Postgres, 0:21 are known as relational databases. 0:26 And databases that store data in documents 0:29 such as MongoDB are known as NoSQL databases. 0:32 In this course, we'll be using the database called SQL Server LocalDB, 0:36 a developer centric version of Microsoft's relational database management 0:41 system SQL Server. 0:45 See the teacher's notes for 0:47 Treehouse courses that can help you deepen your understanding of databases. 0:48 The .NET framework provides rich support for working with databases. 0:52 We can use a part of .NET known as ADO.NET to work with data in relational databases. 0:57 For years, this has been the approach that developers used. 1:04 It generally worked great, though developers often found themselves 1:08 spending time writing a lot of repetitive boilerplate code. 1:13 Additionally SQL statements and queries which are used to work with data in 1:17 relational databases, when expressed in code, are written using strings. 1:21 This prevents Visual Studio from being able to assist the developer 1:27 with detecting syntax errors or 1:30 preventing something as simple as mistyped table or column names. 1:33 Entity Framework offers a way to increase developer productivity 1:37 by making data access code easier to write and more reliable. 1:42 When using Entity Framework, developers interact with a set of models or entities, 1:46 and a database context class to do database operations. 1:51 Instead of interacting directly with the database, 1:55 Entity Framework acts as a mediator, overseeing the movement of data from 1:58 the database to the entity classes and back again. 2:02 Entity Framework, which is commonly referred to simply as EF, 2:06 is a type of framework or library, known as an Object Relational Mapper, or ORM. 2:11 Under the covers, EF uses ADO.NET, 2:18 the same ADO.NET the developers used to use for data access. 2:21 Because of this, EF is sometimes thought of as an abstraction layer atop 2:26 of ADO.NET, though this analogy is somewhat of an oversimplification. 2:31 Entities in EF are just plain old C# Objects or POCO classes. 2:37 Generally speaking, each Entity class represents a table in the database. 2:44 And Entity class properties represent columns and their respective tables. 2:49 Because of this, EF makes working with data from a database very familiar. 2:54 Once data has been retrieved from the database and 2:59 mapped into an Entity object or a collection of entity objects, 3:02 working with that data is just like working with any C# Object. 3:06 EF queries are written using C#'s Language Integrated Query, or 3:12 LINQ, using either the fluent or query syntax. 3:16 LINQ, when used with EF, is known as LINQ to Entities. 3:20 EF translates LINQ queries into the appropriate SQL statements so 3:25 that they can be executed against the database. 3:29 In most cases, this shields you from having to write SQL queries, though having 3:33 a basic understanding of databases in SQL can be helpful when working with ORM's. 3:38 Entity framework can be added to any .NET project using the NuGet Package Manager. 3:44 We'll be using the latest version of EF which at the time of this recording 3:50 is 6.1.3. 3:54 Being a Microsoft Project, EF is typically used with Microsoft SQL Server, 3:55 though other databases are supported through the use of data providers. 4:01 Supported databases include Oracle, MySQL, and Postgres. 4:06 In the next video, we'll see how we can get started with using EF 4:11 by describing the shape of our data and connecting to a database. 4:15
You need to sign up for Treehouse in order to download course files.Sign up