Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
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,
let's take a moment to talk about databases and
the .NET framework support for working with databases.
We'll also take a look at what Indie framework is and
how it offers developers a better way of working with data in their applications.
There are many different kinds of databases.
Databases that store data in tables, such as MySQL or Postgres,
are known as relational databases.
And databases that store data in documents
such as MongoDB are known as NoSQL databases.
In this course, we'll be using the database called SQL Server LocalDB,
a developer centric version of Microsoft's relational database management
system SQL Server.
See the teacher's notes for
Treehouse courses that can help you deepen your understanding of databases.
The .NET framework provides rich support for working with databases.
We can use a part of .NET known as ADO.NET to work with data in relational databases.
For years, this has been the approach that developers used.
It generally worked great, though developers often found themselves
spending time writing a lot of repetitive boilerplate code.
Additionally SQL statements and queries which are used to work with data in
relational databases, when expressed in code, are written using strings.
This prevents Visual Studio from being able to assist the developer
with detecting syntax errors or
preventing something as simple as mistyped table or column names.
Entity Framework offers a way to increase developer productivity
by making data access code easier to write and more reliable.
When using Entity Framework, developers interact with a set of models or entities,
and a database context class to do database operations.
Instead of interacting directly with the database,
Entity Framework acts as a mediator, overseeing the movement of data from
the database to the entity classes and back again.
Entity Framework, which is commonly referred to simply as EF,
is a type of framework or library, known as an Object Relational Mapper, or ORM.
Under the covers, EF uses ADO.NET,
the same ADO.NET the developers used to use for data access.
Because of this, EF is sometimes thought of as an abstraction layer atop
of ADO.NET, though this analogy is somewhat of an oversimplification.
Entities in EF are just plain old C# Objects or POCO classes.
Generally speaking, each Entity class represents a table in the database.
And Entity class properties represent columns and their respective tables.
Because of this, EF makes working with data from a database very familiar.
Once data has been retrieved from the database and
mapped into an Entity object or a collection of energy objects,
working with that data is just like working with any C# Object.
EF queries are written using C#'s Language Integrated Query, or
LINQ, using either the fluent or query syntax.
LINQ, when used with EF, is known as LINQ to Entities.
EF translates LINQ queries into the appropriate SQL statements so
that they can be executed against the database.
In most cases, this shields you from having to write SQL queries, though having
a basic understanding of databases in SQL can be helpful when working with ORM's.
Entity framework can be added to any .NET project using the NuGet Package Manager.
We'll be using the latest version of EF which at the time of this recording
Being a Microsoft Project, EF is typically used with Microsoft SQL Server,
though other databases are supported through the use of data providers.
Supported databases include Oracle, MySQL, and Postgres.
In the next video, we'll see how we can get started with using EF
by describing the shape of our data and connecting to a database.
You need to sign up for Treehouse in order to download course files.Sign up