Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
EF Core uses migrations to track and apply schema changes: You modify your C# models. Use Add-Migration to create a migration class. Use Update-Database to apply the changes to the DB. EF Core compares the model to the c…
🧩 Data Annotations (in the entity class): [Table("Users")] public class User { [Key] public int Id { get; set; } [Column("UserName")] public string Name { get; set; } } 🧠 Fluent API (in OnModelCreating): modelBuilder.E…
Migrations in EF Core are a way to: Track schema changes over time Apply those changes to the database 📦 Basic commands: Add-Migration MigrationName Update-Database Remove-Migration Script-Migration 🔄 Migrations are cl…
How are they used in Code First? Migrations in EF Core are a way to: Track schema changes over time Apply those changes to the database 📦 Basic commands: Add-Migration MigrationName Update-Database Remove-Migration Scri…
Answer: dd-Migration MigrationName This creates a migration file with Up() and Down() methods, and a snapshot of the current model. What interviewers expect A clear definition tied to EF Core in Entity Framework Core pro…
(e.g. Add-Migration) Use one of the following commands: .NET CLI: dotnet ef migrations add MigrationName Package Manager Console: Add-Migration MigrationName This creates a migration file with Up() and Down() methods, an…
Answer: pply the migration to your database using: .NET CLI: dotnet ef database update Package Manager Console: Update-Database EF Core translates your model changes into SQL and executes them against the database. What…
Answer: (e.g. Update-Database) Apply the migration to your database using: .NET CLI: dotnet ef database update Package Manager Console: Update-Database EF Core translates your model changes into SQL and executes them aga…
A migration snapshot is a C# file (e.g., ModelSnapshot.cs) automatically created by EF Core. It represents the current model state. EF uses it to compare changes in future migrations. Located in the Migrations folder, na…
Answer: To remove the last migration before applying it: dotnet ef migrations remove To rollback the database to a previous migration: dotnet ef database update MigrationName To rollback all migrations: dotnet ef databas…
Answer: Generate SQL script using: dotnet ef migrations script To script a specific range: dotnet ef migrations script FromMigration ToMigration These scripts are useful for deploying to production environments or execut…
How to generate SQL scripts for migrations? Generate SQL script using: dotnet ef migrations script To script a specific range: dotnet ef migrations script FromMigration ToMigration These scripts are useful for deploying…
Answer: Use the HasData() method in OnModelCreating(): modelBuilder.Entity<User>().HasData( new User { Id = 1, Name = "Admin" } ); Data is inserted automatically during Update-Database. Changes to seed data…
Best practices: Communicate and coordinate migration changes. Always pull and apply the latest migrations before adding a new one. If conflicts arise: Resolve merge conflicts in migration files manually. Rebuild ModelSna…
Generate SQL script from tested migrations. Manually review and apply via DBA or DevOps tools. Use EF Core tools in CI/CD (e.g., GitHub Actions, Azure DevOps): dotnet ef database update --no-build ● Always backup the dat…
Answer: Scaffolded migrations are the automatically generated classes that contain Up() and Down() methods. They are generated based on model differences. You can manually edit these files to: Add custom SQL Rename colum…
You can manually edit migration files after scaffolding: protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.Sql("UPDATE Users SET IsActive = 1 WHERE IsActive IS NULL"); } Add indexes, constr…
Answer: fter they are loaded from the database. This allows EF Core to generate the correct SQL INSERT, UPDATE, or DELETE statements when SaveChanges() is called. What interviewers expect A clear definition tied to EF Co…
Change tracking is the process by which EF Core keeps track of changes made to entities after they are loaded from the database. This allows EF Core to generate the correct SQL INSERT, UPDATE, or DELETE statements when S…
dded New entity to be inserted into the database Modified Entity has been changed and will be updated Deleted Entity will be deleted from the database Detached Entity is not tracked by the context Unchange No changes hav…
EF Core uses these EntityState values: State Description Added New entity to be inserted into the database Modified Entity has been changed and will be updated Deleted Entity will be deleted from the database Detached En…
Answer: re loaded, and compares them before saving. Notifications: If your entities implement INotifyPropertyChanged, EF can track changes immediately. EF compares the current values to the original snapshot during SaveC…
EF Core tracks changes via: Snapshot change tracking: EF stores a snapshot of original values when entities are loaded, and compares them before saving. Notifications: If your entities implement INotifyPropertyChanged, E…
re monitored and persisted. Untracked queries: EF does not monitor the returned entities. Faster, read-only ccess. Tracked (default): var user = context.Users.FirstOrDefault(); Untracked: var user = context.Users.AsNoTra…
Tracked queries: EF Core tracks entities returned from the query. Changes to them are monitored and persisted. Untracked queries: EF does not monitor the returned entities. Faster, read-only access. Tracked (default): va…
Entity Framework Core Entity Framework Core Tutorial · EF Core
EF Core uses migrations to track and apply schema changes:
EF Core compares the model to the current schema to generate SQL.
Entity Framework Core Entity Framework Core Tutorial · EF Core
🧩 Data Annotations (in the entity class):
[Table("Users")]
public class User
{
[Key]
public int Id { get; set; }
[Column("UserName")]
public string Name { get; set; }
}
🧠 Fluent API (in OnModelCreating):
modelBuilder.Entity<User>()
.ToTable("Users")
.HasKey(u => u.Id);
modelBuilder.Entity<User>()
.Property(u => u.Name)
.HasColumnName("UserName");
📌 Fluent API is more powerful and flexible, preferred for complex configurations.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Migrations in EF Core are a way to:
📦 Basic commands:
🔄 Migrations are classes containing Up() and Down() methods (for applying and reverting
changes).
📌 They are essential for schema versioning in Code First.
Entity Framework Core – Migrations
Interview QuestionsEntity Framework Core Entity Framework Core Tutorial · EF Core
How are they used in Code First?
Migrations in EF Core are a way to:
📦 Basic commands:
🔄 Migrations are classes containing Up() and Down() methods (for applying and reverting
changes).
📌 They are essential for schema versioning in Code First.
Entity Framework Core – Migrations
Interview Questions
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: dd-Migration MigrationName This creates a migration file with Up() and Down() methods, and a snapshot of the current model.
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
(e.g. Add-Migration)
Use one of the following commands:
.NET CLI:
dotnet ef migrations add MigrationName
Package Manager Console:
Add-Migration MigrationName
This creates a migration file with Up() and Down() methods, and a snapshot of the current
model.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: pply the migration to your database using: .NET CLI: dotnet ef database update Package Manager Console: Update-Database EF Core translates your model changes into SQL and executes them against the database.
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: (e.g. Update-Database) Apply the migration to your database using: .NET CLI: dotnet ef database update Package Manager Console: Update-Database EF Core translates your model changes into SQL and executes them against the database.
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
by EF Core.
[YourDbContext]ModelSnapshot.cs.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: To remove the last migration before applying it: dotnet ef migrations remove To rollback the database to a previous migration: dotnet ef database update MigrationName To rollback all migrations: dotnet ef database update 0
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Generate SQL script using: dotnet ef migrations script To script a specific range: dotnet ef migrations script FromMigration ToMigration These scripts are useful for deploying to production environments or executing via CI/CD pipelines.
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
How to generate SQL scripts for
migrations?
Generate SQL script using:
dotnet ef migrations script
To script a specific range:
dotnet ef migrations script FromMigration ToMigration
These scripts are useful for deploying to production environments or executing via CI/CD
pipelines.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Use the HasData() method in OnModelCreating(): modelBuilder.Entity<User>().HasData( new User { Id = 1, Name = "Admin" } ); Data is inserted automatically during Update-Database. Changes to seed data require a new migration.
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Best practices:
Entity Framework Core Entity Framework Core Tutorial · EF Core
Use EF Core tools in CI/CD (e.g., GitHub Actions, Azure DevOps):
dotnet ef database update --no-build
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Scaffolded migrations are the automatically generated classes that contain Up() and Down() methods. They are generated based on model differences. You can manually edit these files to: Add custom SQL Rename columns Seed data, etc.
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
You can manually edit migration files after scaffolding:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("UPDATE Users SET IsActive = 1 WHERE
IsActive IS NULL");
}
Entity Framework Core – Change
Tracking & Concurrency
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: fter they are loaded from the database. This allows EF Core to generate the correct SQL INSERT, UPDATE, or DELETE statements when SaveChanges() is called.
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Change tracking is the process by which EF Core keeps track of changes made to entities
after they are loaded from the database. This allows EF Core to generate the correct SQL
INSERT, UPDATE, or DELETE statements when SaveChanges() is called.
Entity Framework Core Entity Framework Core Tutorial · EF Core
dded New entity to be inserted into the database
Modified Entity has been changed and will be updated
Deleted Entity will be deleted from the database
Detached Entity is not tracked by the context
Unchange
No changes have been made since it was
loaded
You can check/set the state via:
context.Entry(entity).State = EntityState.Modified;Entity Framework Core Entity Framework Core Tutorial · EF Core
EF Core uses these EntityState values:
State Description
Added New entity to be inserted into the database
Modified Entity has been changed and will be updated
Deleted Entity will be deleted from the database
Detached Entity is not tracked by the context
Unchange
No changes have been made since it was
loaded
You can check/set the state via:
context.Entry(entity).State = EntityState.Modified;
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: re loaded, and compares them before saving. Notifications: If your entities implement INotifyPropertyChanged, EF can track changes immediately. EF compares the current values to the original snapshot during SaveChanges().
In a production Entity Framework Core application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
EF Core tracks changes via:
are loaded, and compares them before saving.
changes immediately.
EF compares the current values to the original snapshot during SaveChanges().
Entity Framework Core Entity Framework Core Tutorial · EF Core
re monitored and persisted.
ccess.
Tracked (default):
var user = context.Users.FirstOrDefault();
Untracked:
var user = context.Users.AsNoTracking().FirstOrDefault();Entity Framework Core Entity Framework Core Tutorial · EF Core
are monitored and persisted.
access.
Tracked (default):
var user = context.Users.FirstOrDefault();
Untracked:
var user = context.Users.AsNoTracking().FirstOrDefault();