Accessing Data Using Entity Framework Core 3

We have come a long way with our implementation of the Tic-Tac-Toe demo web application, but when we restart the application, none of our user registration and application data is remembered. This is due to the fact that we are not saving or persisting any data yet.

To persist data and be able to reload it when the application starts, we have to put it into some kind of persistent storage, such as files (XML, JSON, CSV) or databases.

A database would be the best choice since it provides better performance and more security compared to simple file storage, and that is why we are going to use this approach in the examples in this chapter.

Since the old ASP.NET 3 days, we have been able to use an object-relational mapping (ORM) framework called Entity Framework to access data in databases in a more productive and simple way. ASP.NET Core 3 works seamlessly with a dedicated version of this framework called Entity Framework Core 3, part of Entity Framework 6.3, and can also work with previous versions.

We will start this chapter by introducing Entity Framework Core 3.0 and how to install it. Then, we will learn about all the classes we need in order to use a code-first approach to create the database, after which we will show you how to perform migrations. Next, we'll explore normal CRUD operations and explain the most common and important data relationships. Finally, we will explain queries in slightly greater depth and introduce transactions.

By the end of this chapter, you will be able to connect to a database using Entity Framework Core, use migrations with updates, carry out basic CRUD operations, work with the Fluent API, perform complex queries against a database, and use transactions.

In this chapter, we will cover the following topics: 

  • Getting started with Entity Framework Core 3
  • Working with Entity Framework Core 3 Data Annotations
  • Using Entity Framework Core 3 migrations
  • Creating, reading, updating, and deleting data
  • Understanding data relationships
  • Working with queries
  • Using transactions
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.123.208