Entity Framework Core Interview

Change Tracking, Updates, Transactions & Concurrency

Entity Framework Core interview questions covering change tracking, disconnected updates, transactions, savepoints and optimistic concurrency.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
101
Mid-LevelIntermediate

What is change tracking in EF Core?

Change tracking is EF Core's mechanism for monitoring entity instances and their state so it can determine which INSERT, UPDATE, or DELETE commands are required when SaveChanges is called.

102
Mid-LevelIntermediate

How does EF Core detect changes to tracked entities?

EF Core commonly uses snapshot change detection. When an entity starts being tracked, EF Core records original values. During change detection it compares current values with those originals to determine which properties changed.

103
Mid-LevelIntermediate

What is the EF Core ChangeTracker?

ChangeTracker provides access to information and operations for entities currently tracked by a DbContext. It can inspect entries, entity states, original/current values, tracked relationships, and change-detection behavior.

104
Mid-LevelIntermediate

What are original values and current values in EF Core?

For tracked entities, EF Core can maintain the values originally loaded from the database and the values currently present on the entity.

105
Mid-LevelIntermediate

How can you determine which properties of an entity are modified?

Each tracked property entry exposes an IsModified flag. EF Core sets it when change detection identifies a modification, and application code can also set it explicitly.

106
Mid-LevelIntermediate

What is AsNoTracking and when should it be used?

AsNoTracking tells EF Core not to track entities returned by a query. It is well suited to read-only pages, reports, and API responses where the entities will not be modified through the same context.

107
Mid-LevelIntermediate

What is AsNoTrackingWithIdentityResolution?

AsNoTrackingWithIdentityResolution performs a no-tracking query while ensuring that repeated occurrences of the same entity identity in the query result are represented by the same object instance within that result materialization.

108
Mid-LevelIntermediate

What is a disconnected entity scenario in EF Core?

A disconnected scenario occurs when an entity is read using one DbContext but later modified or submitted when that context no longer exists. ASP.NET Core web applications commonly work this way because each request typically has a separate scoped DbContext.

109
Mid-LevelIntermediate

Why can blindly calling Update on a disconnected entity be risky?

Update generally marks the entity and appropriate reachable graph members as modified. With client-supplied models, this can cause more columns or related entities to be updated than intended.

110
Mid-LevelIntermediate

How can EF Core perform a targeted update without loading the complete entity?

A stub entity containing the key can be attached, and selected properties can be marked as modified. This can avoid a preliminary SELECT when the application already has enough trustworthy information.

111
Mid-LevelIntermediate

What is ExecuteUpdate in EF Core?

ExecuteUpdate performs a set-based database UPDATE directly from a LINQ query without first loading matching entities into the change tracker.

112
Mid-LevelIntermediate

What is ExecuteDelete in EF Core?

ExecuteDelete performs a set-based DELETE directly in the database for rows matching a LINQ query. The entities do not need to be loaded or tracked first.

113
Mid-LevelIntermediate

What is a transaction in EF Core?

A database transaction groups operations into a unit that either commits successfully or is rolled back. Transactions protect consistency when multiple related database changes must succeed together.

114
Mid-LevelIntermediate

Does SaveChanges use a transaction automatically?

For relational databases that support transactions, EF Core normally wraps the changes in a single SaveChanges call in a transaction. If a command fails, the transaction can roll back so the group of changes is not partially committed.

115
Mid-LevelIntermediate

How do you create an explicit transaction in EF Core?

Use Database.BeginTransaction or BeginTransactionAsync to create a transaction. Perform the required operations, then explicitly commit. If an exception occurs before commit, roll back or allow disposal to end the uncommitted transaction according to provider behavior.

116
Mid-LevelIntermediate

What is a savepoint in EF Core transactions?

A savepoint marks a point inside an existing transaction to which work can be rolled back without necessarily aborting the entire transaction.

117
Mid-LevelIntermediate

What is optimistic concurrency in EF Core?

Optimistic concurrency assumes conflicting updates are relatively uncommon. Instead of locking a row for the entire user workflow, EF Core includes a concurrency token in the UPDATE or DELETE condition.

118
Mid-LevelIntermediate

What is a concurrency token in EF Core?

A concurrency token is a property whose original value participates in the condition used for UPDATE or DELETE operations. It helps EF Core detect whether the database row changed since the entity was originally read.

119
Mid-LevelIntermediate

What is rowversion and how is it used with EF Core on SQL Server?

SQL Server rowversion is a database-generated binary value that changes when a row is updated. EF Core can map it as a concurrency token.

120
Mid-LevelIntermediate

How do you handle DbUpdateConcurrencyException?

Catch DbUpdateConcurrencyException around SaveChanges when the application uses optimistic concurrency. Inspect the affected entries and retrieve current database values if needed.

121
Mid-LevelIntermediate

What is the difference between optimistic and pessimistic concurrency?

Optimistic concurrency allows multiple users to read data without holding long-lived locks and detects conflicts when an update is attempted. EF Core directly supports this pattern through concurrency tokens.

122
Mid-LevelIntermediate

How do transactions interact with external services such as payment APIs?

A database transaction cannot normally make an external HTTP service participate in the same atomic local transaction. Holding a database transaction open while waiting for an external API also increases lock duration and failure complexity.

123
Mid-LevelIntermediate

What is the outbox pattern and how does it relate to EF Core transactions?

The outbox pattern stores a business data change and a message-to-be-published in the same database transaction. After commit, a background process reads the outbox and publishes the message to the external broker or service.

124
Mid-LevelIntermediate

How can SaveChanges be customized for auditing fields?

A DbContext can inspect tracked entries before SaveChanges and populate fields such as CreatedAtUtc and UpdatedAtUtc. This centralizes common persistence metadata instead of repeating it in every service.

125
Mid-LevelIntermediate

What are best practices for EF Core updates, transactions, and concurrency?

Use tracked entities for straightforward unit-of-work updates, but use no-tracking queries for read-only workloads. In disconnected web requests, load the authoritative entity and map only permitted changes instead of blindly updating client-supplied graphs.