.Net EF Core Flashcards
How to migrate database changes from EF core to database?
Using database migrations , by running commands or by calling migrate method in startup of the application
What happens when you write filtering , sorting , paging before execute command?
The query runs inside DB instead of in code which improves the performance of query
What are the two types of queries ?
- Normal, read-write query
2.AsNoTracking, read-only query
What are different types of loading data?
Eager loading, Explicit loading, Select loading, Lazy loading
Will EFCore load relationships by default?
No , it will not . By default , they will be null
What is Eager loading?
Eager loading is when you query one type of entity and immediately load related entities as part of it. Eager loading is specified via two fluent methods , Include and thenInclude
What is the issue with eager loading?
If you do not specify .Include() , no related entities are loaded or only partial set may be loaded if previously some related entities are loaded
What is the advantage of eager loading?
Loads all the data of the related entity using minimum database round trips
What is the disadvantage of eager loading?
Since it loads all the data of the related entity , in some cases you might do not want to load all of the columns
What are the linq methods you can add in your Include() methods?
Where, OrderBy, OrderByDescending, ThenBy, ThenByDescending, Skip and Take
What is explicit loading?
After loading primary entity class , you can explicitly load any other relationships using Load() method
What is the issue with explicit loading?
A seperate db query is run each time you call load() . So if you were to load table of N records then N+1 queries need to be processed instead of just one query in case of eager loading
What is the disadvantage of explicit loading?
More database round trips compared to eager loading. If you know upfront that you need related entities use eager loading as it takes fewer round trips . On the other hand you know you need to load related entities for fewer instances use explicit loading
What is select loading?
Use the select linq method to select few standard properties from entity and its related entity.
What is advantage of select loading?
Only the required properties are loaded