Entity Framework Core is an ORM, or object‑relational mapper.
Object‑relational mapping is a technique that lets you query and manipulate
data from a database using an object‑oriented paradigm.
So,
in our code, we can work on objects rather than directly writing
SQL statements in our code. Relational models and object models
do not work very well together.
A relational database represents data in a tabular format.
Object‑oriented languages, on the other hand,
represent it as an interconnected graph of objects.
It's the ORM,
the library that implements the object‑relational mapping technique,
like Entity Framework Core, that takes care of this. Needless to say,
that is a big plus. In very simple cases,
those objects map directly to your database tables, like in
our demo. We've got a city and a point of interest, and
that's about it. But in larger,
more complicated pieces of software, this OO technique allows us to
implement object‑oriented functionality like inheritance. A base
Person class and an Employee class that inherits Person can map to
data stored in the same table in the database. Or better granularity
without inheritance.
A table in a database might translate to a different
set of classes in an OO model.
The entities the ORM works with are different than a one‑on‑one mapping
to tables. Entity Framework Core comes with a set of providers, so you
can use it with a variety of databases. There's quite a few of these
available, and we're looking at the list now. We can work with Microsoft
SQL Server, of course, but also SQLite, Postgres, MySQL, and so on.
We're going to use SQLite in this course because that's a provider that is
supported on all platforms and by all IDEs. Like that,
it doesn't matter whether you're following this course on Mac,
Linux, or Windows. You will be able to follow along. That being
said, if you want to use SQL Server,
MySQL, or another provider, the concepts and reasoning
you will learn are exactly the same.
You can use Entity Framework Core with a code‑first approach, which will create
the database from our code, and a database‑first approach,
which is convenient if you've already got a database. We haven't got a database
yet, so in our demos we will take the code‑first approach. Let's get started with the first demo.