My Web Markups - jamal shahidi
In this step, the Context is created. Context is like a session with a database for all database operations (Create, Retrieve, Update and Delete). Context is responsible for following tasks, Query Execution on the connection. Tracking the changes made to the entity after data retrieval Persisting object changes to the database. Caching The materialization of data to object/ entity
Step 1 - Context Creation
Based on this diagram, we can categorize all execution cycle into 3 stages: Context Creation Query Expression Creation Query Execution
All The Steps For Query Execution In Entity Framework
When you’re doing something for the first time, just get it done. When you’re doing something similar for the second time, cringe at having to repeat but do the same thing anyway. When you’re doing something for the third time, start refactoring.
Rule of Three
When to refactor
The AsNoTracked query doesn’t take a copy so it isn’t tracked – this means its faster than a normal query. This also means it won’t be considered for database writes
This normal query also has some sophisticated code called relational fixup which fills in any links between the entity classes read in, and any other tracked entities.
The normal query also takes a copy of any data it reads in inside the application’s DbContext – the entity classes are said to be tracked. This allows the loaded entity classes to take part in commands to update the database
Both types of query return classes (referred to as entity classes) with links to any other entity classes (known as navigational properties) loaded at the same time. But how and what they are linked to is different between the two types of queries
(known as a query): a normal LINQ query and a LINQ query that contains the method AsNoTracking
EF Core has two ways to read data from the database
EF Core In depth – what happens when EF Core reads from the database? – The Reformed Programmer