Tutorial: Get Started with Entity Framework


Tutorial: Get Started with Entity Framework
Tutorial: Get Started with Entity Framework Image Source: Code With Mukesh
Spread the love

What is Entity Framework Core?

Entity Framework Core has been created to provide developers with the tools to build applications that can interact with SQL databases. The current version is EF Core 6.0, released in November 2021. Entity Framework is a library that allows developers to programmatically access data stored in databases. This library is used to store data in relational databases, including Microsoft SQL Server, MySQL, and PostgreSQL. It’s been designed to enable developers to use existing classes to easily access the data stored in a database. It supports object-relational mapping, which is a technique for converting the data that is stored in a database into classes. This can be used by developers who want to use the data in their applications without having to write lots of extra code.

How to use Entity Framework Core ORM?

ORMs provide a solution to the problem of mapping objects to databases. An ORM can be used to create relationships between objects and entities in the data source. The ORM can automatically generate the database tables and foreign keys. This is very helpful because it eliminates the need for manual programming to define table structures. Entity Framework Core ORM uses an approach known as the “object-relational mapping” approach. This approach allows developers to treat the database as an object repository and develop the application using an object-oriented approach.

In relational database recordsets, you’ll usually need to use a query language to access information from them.

See also  "Unlocking Growth: The Function of a Fractional CMO in Fintech Software as a Service" is the

For example, we need to get a list of students from the database. We can do it through ADO.NET:

SzZTxRuQ6iMpLwYWD6TLhnTkShZUMNxFuHKK8Q8Teu CvzQ1ZaQ7c4446yEfn5QgtioH6XnrgN9WAps sok4FHtQ3Z1y6IZE3sGsk1jmOaLkWeh0oPSz6fGukqS3fanR8I sE2Sce7VSPYRhyWtWBtOFALB44n61IXIJkeNDMVBirFhnKzIC6P1Wm8vgg

The problem is, this approach to data access is prone to errors. This could have compile-time errors or it could run perfectly well. There are many types of code errors, and this is a common one. We might address columns that were removed or with incorrect column names.

In strongly-typed programming, data structures are used to organize data and provide it to programs.

TiWjHFX7nQkL2E Hix1jSi9sPrjBl9D2d 5vsvLSkFz92sb7a6GiWqM Tcbibc5ImH8rx84x6a5hGSAj5IqBdni NhyTott1

We’ll have to retrieve the data from the database and map it to our data model.

Entity Framework Core ORM comes in handy when you need to write queries against the database.

ORMs make sure that the Domain Model is mapped to the database. They also ensure that the database is properly designed and updated as needed. They can manage transactions, keep track of already retrieved objects and provide an API to create, retrieve, update, delete and delete objects.

tI4 CyUssWrTlExM66wWjSSuKIiS6vTlGKwcdYp4n4ekuFMN6o3cPS1slOpMjkk7dmKluuFwlghkrFCQpNYKFh9g6 SAJjEpKpicFzuDBjHmh1CWoA

Entity Framework Core Architecture

To understand the EF Core hierarchy, you need to start with its components. Look at the Entity Framework architecture:

1. Data source-specific providers;

2. Map provider;

3. EDM parser and view mapping;

4. Query and update pipeline;

5. Metadata services;

6. Transactions;

7. Conceptual layer API;

8. Disconnected components;

9. Embedded database;

10. Design tools;

11. Programming layer;

12. Object services;

13. Web services;

14. High-level services. 

Entity Framework Core Versions

Entity Framework Core was born in 2016. By this time, it was many versions of EF Core: EF Core 1.0, 2.0, 3.0, 3.1, 5.0.2, 6.0

See also  International News Platform Beijing Times Broadens Reach with Strategic Expansion in Dubai and Paris

The latest version is EF Core 6.0.7. Here is a short list of the changes in this version:

  • SQL Server temporal tables
  • Migration Bundles
  • Pre-convention model configuration
  • Compiled models
  • Improved performance on TechEmpower Fortunes
  • Improvements to scaffolding from an existing database
  • LINQ query enhancements
  • New mapping attributes
  • Model building improvements
  • DbContext factory improvements
  • Miscellaneous improvements

Spread the love

Twinkle Jain