Lyra
Learn
AI Learning Platform
π Midnight
π Comfort
π₯ Ember
π Paper
β Contrast
Exams
Sign in to track progress
β Back to the lesson
Module 4 Β· Quiz
Tracking and DbContext Lifetime
1. What does `AsNoTracking()` do in EF Core?
Skips the snapshot, allowing for faster reads and lower memory usage
Generates a new DbContext instance
Saves all changes to the database immediately
Tracks changes to entities for performance improvement
2. Why might an entity not save when calling `SaveChanges()`?
The entity was loaded using `AsNoTracking()`
The entity is used in multiple contexts
The entity was never retrieved from the database
The context is a singleton instance
3. What is a consequence of injecting a scoped DbContext into a singleton?
It causes performance issues
It creates a new instance for each request
It can throw an exception or behave like a singleton
It allows parallel execution of queries
4. How should a DbContext be used within a `BackgroundService` to avoid issues?
Inject it as a singleton for improved performance
Create a new instance on each request
Use `IDbContextFactory<T>` to create a scoped DbContext
Load it from the service container without managing its lifecycle
Submit answers
Continue: Transactions and Concurrency β
Review this lesson
Retake quiz