Here, you will see an overview of how entity framework works.
Entity Framework API (EF6 & EF Core) includes the ability to map domain (entity) classes to the database schema, translate & execute LINQ queries to SQL, track changes occurred on entities during their lifetime, and save changes to the database.
The very first task of EF API is to build an Entity Data Model (EDM). EDM is an in-memory representation of the entire metadata: conceptual model, storage model, and mapping between them.
Conceptual Model: EF builds the conceptual model from your domain classes, context class, default conventions followed in your domain classes, and configurations.
Storage Model: EF builds the storage model for the underlying database schema. In the code-first approach, this will be inferred from the conceptual model. In the database-first approach, this will be inferred from the targeted database.
Mappings: EF includes mapping information on how the conceptual model maps to the database schema (storage model).
EF performs CRUD operations using this EDM. It uses EDM in building SQL queries from LINQ queries, building INSERT, UPDATE, and DELETE commands, and transform database result into entity objects.
EF API translates LINQ-to-Entities queries to SQL queries for relational databases using EDM and also converts results back to entity objects.
EF API infers INSERT, UPDATE, and DELETE commands based on the state of entities when the
SaveChanges() method is called.
The ChangeTrack keeps track of the states of each entity as and when an action is performed.
Here you will learn about the basic CRUD workflow using Entity Framework.
The following figure illustrates the basic workflow.
Let's understand the above EF workflow:
SaveChanges()method. EF API will build an appropriate INSERT command and execute it to the database.
SaveChanges()method. EF API will build the appropriate UPDATE or DELETE command and execute it to the database.