Technical interview Q&A plus 100+ career & HR questions—notice period, salary negotiation, resume, LinkedIn, freelancing, AI careers, and behavioral interviews with detailed, real-world answers.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Entity Framework Core (EF Core) is a modern, lightweight, cross-platform, open-source ORM (Object-Relational Mapper) for .NET. It allows developers to interact with databases using C# objects rather than SQL queries.
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
Feature EF6 EF Core
Platform .NET Framework only Cross-platform (.NET Core)
Performance Slower Faster and more optimized
LINQ support Limited Enhanced
Change
tracking
Basic More efficient
Migrations Available Improved and CLI-friendly
Extensibility Limited Highly extensible
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: How does EF Core implement it? ORM is a technique that maps objects in code to relational database tables. EF Core implements ORM by mapping .NET classes (entities) to database tables using DbContext, DbSet, and conventions or Fluent API.
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: ORM is a technique that maps objects in code to relational database tables. EF Core implements ORM by mapping .NET classes (entities) to database tables using DbContext, DbSet, and conventions or Fluent API.
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
What responsibilities does it have?
DbContext is the primary class for interacting with the database in EF Core. It:
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: DbContext is the primary class for interacting with the database in EF Core. It: Manages database connections Tracks changes to entities Provides methods for querying and saving data Configures models and relationships
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: How does it map to database tables? DbSet<T> represents a collection of entities of type T in the context. Each DbSet maps to a table in the database, where T is the type of the entity.
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: DbSet<T> represents a collection of entities of type T in the context. Each DbSet maps to a table in the database, where T is the type of the entity.
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: Entities are .NET classes that represent database tables. Each property in the entity maps to a column. EF Core uses conventions or Fluent API to configure the mappings.
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
column. EF Core uses conventions or Fluent API to configure the mappings.
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: POCO (Plain Old CLR Object) is a simple class without any dependency on EF Core or any base class. EF Core uses POCOs as entities for data modeling.
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
Navigation properties allow navigation from one entity to related entities. They define
relationships (one-to-one, one-to-many, many-to-many).
Example:
public class Order
{
public int Id { get; set; }
public Customer Customer { get; set; } // Navigation property
}Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Scalar: Simple types like int, string, DateTime Complex: Nested objects mapped to multiple columns (Value objects) Shadow: Properties not defined in the .NET class but tracked by EF Core
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: LINQ (Language Integrated Query) lets you query collections using C# syntax. LINQ to Entities is LINQ querying against the EF Core model, translated to SQL and executed in 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: What is “LINQ to Entities”? LINQ (Language Integrated Query) lets you query collections using C# syntax. LINQ to Entities is LINQ querying against the EF Core model, translated to SQL and executed in 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
// Create
context.Users.Add(new User { Name = "John" });
context.SaveChanges();
// Read
var user = context.Users.FirstOrDefault(u => u.Id == 1);
// Update
user.Name = "Jane";
context.SaveChanges();
// Delete
context.Users.Remove(user);
context.SaveChanges();
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Productivity via abstraction from SQL Cross-platform support Strongly-typed LINQ queries Migration support Tracks changes automatically Works well with dependency injection
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
Entity Framework Core – Schema Design &
Migrations Interview Questions
Entity Framework Core Entity Framework Core Tutorial · EF Core
Code First is an EF Core approach where you define your database schema using C#
classes, and EF Core generates the database from your code.
✅ Advantages:
📌 When to use:
When you're starting a new project or prefer designing schema in code.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Advantages and when to use it
Code First is an EF Core approach where you define your database schema using C#
classes, and EF Core generates the database from your code.
✅ Advantages:
📌 When to use:
When you're starting a new project or prefer designing schema in code.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Use‑cases and pros and cons
Database First involves generating C# entity classes and a DbContext from an existing
database.
✅ Pros:
❌ Cons:
📌 When to use:
For integrating with existing databases or legacy systems.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Database First involves generating C# entity classes and a DbContext from an existing
database.
✅ Pros:
❌ Cons:
📌 When to use:
For integrating with existing databases or legacy systems.Entity Framework Core Entity Framework Core Tutorial · EF Core
Is it used in EF Core?
Model First allows creating a database model using a designer (EDMX file), then generating
both the database and code from that model.
⚠ EF Core does not support Model First. This approach was available in EF6 with Visual
Studio tooling.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Model First allows creating a database model using a designer (EDMX file), then generating both the database and code from that model. ⚠ EF Core does not support Model First. This approach was available in EF6 with Visual Studio tooling.
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
Use the CLI or Package Manager Console:
dotnet ef dbcontext scaffold "YourConnectionString"
Microsoft.EntityFrameworkCore.SqlServer -o Models
OR
Scaffold-DbContext "YourConnectionString"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
✅ It generates:
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
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
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
(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: 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
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
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
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
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
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
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();
Entity Framework Core Entity Framework Core Tutorial · EF Core
.AsNoTracking() tells EF Core not to track entities in the returned query.
✅ Use when:
Example:
var users = context.Users.AsNoTracking().ToList();Entity Framework Core Entity Framework Core Tutorial · EF Core
When to use it?
.AsNoTracking() tells EF Core not to track entities in the returned query.
✅ Use when:
Example:
var users = context.Users.AsNoTracking().ToList();
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: You can disable tracking by default for a specific DbContext using: optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTrac king); Or per-query using .AsNoTracking().
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
Use the Entry() method:
context.Entry(entity).State = EntityState.Modified;
context.Entry(entity).State = EntityState.Detached;
This is helpful when:
Entity Framework Core Entity Framework Core Tutorial · EF Core
before saving using concurrency tokens.
supported out-of-the-box in EF Core).
EF Core supports optimistic concurrency using [ConcurrencyCheck] or
[Timestamp].
Entity Framework Core Entity Framework Core Tutorial · EF Core
What is optimistic concurrency vs
pessimistic concurrency?
before saving using concurrency tokens.
supported out-of-the-box in EF Core).
EF Core supports optimistic concurrency using [ConcurrencyCheck] or
[Timestamp].
Entity Framework Core Entity Framework Core Tutorial · EF Core
concurrency token is a property used to detect concurrency conflicts.
Example with [Timestamp]:
[Timestamp]
public byte[] RowVersion { get; set; }
DbUpdateConcurrencyException.
Entity Framework Core – Relationships
Entity Framework Core Entity Framework Core Tutorial · EF Core
EF Core supports the standard types of relationships:
Each of these can be configured in EF Core using navigation properties and Fluent API or
Data Annotations.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Example using Fluent API:
modelBuilder.Entity<User>()
.HasOne(u => u.Profile)
.WithOne(p => p.User)
.HasForeignKey<Profile>(p => p.UserId);
Or with data annotations:
public class Profile
{
[Key, ForeignKey("User")]
public int UserId { get; set; }
public User User { get; set; }
}
Entity Framework Core Entity Framework Core Tutorial · EF Core
Fluent API:
modelBuilder.Entity<Blog>()
.HasMany(b => b.Posts)
.WithOne(p => p.Blog)
.HasForeignKey(p => p.BlogId);
Data annotations:
public class Post
{
public int BlogId { get; set; }
[ForeignKey("BlogId")]
public Blog Blog { get; set; }
}
Entity Framework Core Entity Framework Core Tutorial · EF Core
In EF Core 5.0+, you can define many-to-many relationships without an explicit join entity:
public class Student
{
public ICollection<Course> Courses { get; set; }
}
public class Course
{
public ICollection<Student> Students { get; set; }
}
EF will automatically create a join table CourseStudent behind the scenes.
If you want to customize the join table, define a join entity explicitly.Entity Framework Core Entity Framework Core Tutorial · EF Core
join table maps a many-to-many relationship. In EF Core:
✅ Auto-created (EF Core 5+):
If you define many-to-many with ICollection<T>, EF creates the join table.
🛠 Manual (custom join entity):
public class StudentCourse
{
public int StudentId { get; set; }
public Student Student { get; set; }
public int CourseId { get; set; }
public Course Course { get; set; }
}
nd configure with Fluent API.
Entity Framework Core Entity Framework Core Tutorial · EF Core
How to represent them in EF
Core?
A join table maps a many-to-many relationship. In EF Core:
✅ Auto-created (EF Core 5+):
If you define many-to-many with ICollection<T>, EF creates the join table.
🛠 Manual (custom join entity):
public class StudentCourse
public int StudentId { get; set; }
public Student Student { get; set; }
public int CourseId { get; set; }
public Course Course { get; set; }
And configure with Fluent API.
Entity Framework Core Entity Framework Core Tutorial · EF Core
nnotations & Fluent API?
Data Annotations:
[Key]
public int Id { get; set; }
[ForeignKey("Blog")]
public int BlogId { get; set; }
Fluent API:
modelBuilder.Entity<Post>()
.HasKey(p => p.Id);
modelBuilder.Entity<Post>()
.HasOne(p => p.Blog)
.WithMany(b => b.Posts)
.HasForeignKey(p => p.BlogId);Entity Framework Core Entity Framework Core Tutorial · EF Core
How to define them via
annotations & Fluent API?
Data Annotations:
[Key]
public int Id { get; set; }
[ForeignKey("Blog")]
public int BlogId { get; set; }
Fluent API:
modelBuilder.Entity<Post>()
.HasKey(p => p.Id);
modelBuilder.Entity<Post>()
.HasOne(p => p.Blog)
.WithMany(b => b.Posts)
.HasForeignKey(p => p.BlogId);
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: composite key is a primary key made of multiple columns. EF Core does not support composite keys via data annotations, so you must use Fluent PI: modelBuilder.Entity<OrderDetail>() .HasKey(od => new { od.OrderId, od.ProductId });
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
Cascade delete ensures that related entities are deleted when the parent entity is deleted.
Configure with Fluent API:
modelBuilder.Entity<Blog>()
.HasMany(b => b.Posts)
.WithOne(p => p.Blog)
.OnDelete(DeleteBehavior.Cascade);
Delete behaviors:
EF Core defaults to Cascade for required relationships.
Entity Framework Core Entity Framework Core Tutorial · EF Core
shadow property is a property not defined in the .NET class but exists in the EF model.
Example:
modelBuilder.Entity<Post>()
.HasOne<Blog>()
.WithMany()
.HasForeignKey("BlogId"); // BlogId is a shadow FK if not
defined in class
EF tracks it internally but you can't access it in C# code directly.
Entity Framework Core Entity Framework Core Tutorial · EF Core
In Fluent API:
.HasRequired(p => p.Blog)
.HasOne(p => p.Blog)
.WithMany()
.IsRequired(false);
EF infers:
Entity Framework Core – Lazy vs
Eager vs Explicit Loading
Entity Framework Core Entity Framework Core Tutorial · EF Core
Eager loading loads related data as part of the initial query, reducing round-trips to the
database.
✅ Use .Include() to load related entities:
var blogs = context.Blogs
.Include(b => b.Posts)
.ToList();
Use .ThenInclude() for deeper nesting:
context.Blogs
.Include(b => b.Posts)
.ThenInclude(p => p.Comments);
Eager loading prevents lazy load performance issues and the N+1 problem.
Entity Framework Core Entity Framework Core Tutorial · EF Core
How is .Include() / .ThenInclude()
used?
Eager loading loads related data as part of the initial query, reducing round-trips to the
database.
✅ Use .Include() to load related entities:
var blogs = context.Blogs
.Include(b => b.Posts)
.ToList();
Use .ThenInclude() for deeper nesting:
context.Blogs
.Include(b => b.Posts)
.ThenInclude(p => p.Comments);
Eager loading prevents lazy load performance issues and the N+1 problem.
Entity Framework Core Entity Framework Core Tutorial · EF Core
re proxies?
Lazy loading delays the loading of related data until it's accessed for the first time.
EF Core requires proxies for lazy loading:
Install NuGet:
Microsoft.EntityFrameworkCore.Proxies
options.UseLazyLoadingProxies();
public virtual ICollection<Post> Posts { get; set; }
ccessed.
Entity Framework Core Entity Framework Core Tutorial · EF Core
How to enable lazy loading in EF Core? What
are proxies?
Lazy loading delays the loading of related data until it's accessed for the first time.
EF Core requires proxies for lazy loading:
Install NuGet:
Microsoft.EntityFrameworkCore.Proxies
Enable in OnConfiguring or AddDbContext:
options.UseLazyLoadingProxies();
Mark navigation properties as virtual:
public virtual ICollection<Post> Posts { get; set; }
EF creates runtime proxies to override navigation properties and load them when
accessed.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Explicit loading means loading related data manually, after the main entity is loaded.
Use when:
Example:
var blog = context.Blogs.First();
context.Entry(blog)
.Collection(b => b.Posts)
.Load();
context.Entry(blog)
.Reference(b => b.Owner)
.Load();
✅ Use .Reference().Load() for single navigation
✅ Use .Collection().Load() for collections
Entity Framework Core Entity Framework Core Tutorial · EF Core
When & how to use it?
Explicit loading means loading related data manually, after the main entity is loaded.
Use when:
Example:
var blog = context.Blogs.First();
context.Entry(blog)
.Collection(b => b.Posts)
.Load();
context.Entry(blog)
.Reference(b => b.Owner)
.Load();
✅ Use .Reference().Load() for single navigation
✅ Use .Collection().Load() for collections
Entity Framework Core Entity Framework Core Tutorial · EF Core
The N+1 problem occurs when:
Example (lazy loading):
foreach (var blog in context.Blogs)
{
Console.WriteLine(blog.Owner.Name); // triggers a query for each
blog
}
This causes N+1 queries, which can hurt performance significantly.
✅ Solution: Use eager loading with .Include() to fetch everything in one query.
Entity Framework Core Entity Framework Core Tutorial · EF Core
How can lazy loading lead to it?
The N+1 problem occurs when:
Example (lazy loading):
foreach (var blog in context.Blogs)
Console.WriteLine(blog.Owner.Name); // triggers a query for each
blog
This causes N+1 queries, which can hurt performance significantly.
✅ Solution: Use eager loading with .Include() to fetch everything in one query.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Loading
Type
Pros Cons
Eager Fewer queries, good for large data
sets
Loads everything even if not used
Lazy Loads only when needed Risk of N+1 queries, more
round-trips
Explicit Fine-grained control More code complexity
✅ Eager is best for performance when you know you'll need related data.
❌ Lazy can hurt performance unless used carefully (e.g., in UI apps).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: How? Yes. You can disable lazy loading globally: options.UseLazyLoadingProxies(false); Or don't install the proxy package at all. You can also disable it for specific navigation properties by not making them virtual.
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: Yes. You can disable lazy loading globally: options.UseLazyLoadingProxies(false); Or don't install the proxy package at all. You can also disable it for specific navigation properties by not making them virtual.
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 default, EF Core uses no automatic loading — it doesn’t lazy-load or eager-load
relationships unless you:
This default avoids unintended queries and promotes performance control.
EF Core LINQ Queries & Querying
Entity Framework Core Entity Framework Core Tutorial · EF Core
What limitations are there?
cause runtime exceptions.
Entity Framework Core Entity Framework Core Tutorial · EF Core
cause runtime exceptions.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
var query = from c in context.Customers
join o in context.Orders on c.Id equals o.CustomerId
select new { c.Name, o.OrderDate };
var query = from c in context.Customers
join o in context.Orders on c.Id equals o.CustomerId
into orders
from o in orders.DefaultIfEmpty()
select new { c.Name, OrderDate = o != null ? o.OrderDate
: (DateTime?)null };
Entity Framework Core Entity Framework Core Tutorial · EF Core
var groupedData = context.Orders
.GroupBy(o => o.CustomerId)
.Select(g => new
{
CustomerId = g.Key,
TotalOrders = g.Count(),
TotalAmount = g.Sum(o => o.Amount),
MaxAmount = g.Max(o => o.Amount),
MinAmount = g.Min(o => o.Amount)
});
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Filtering: var filtered = context.Products.Where(p => p.Price > 100); Ordering: var ordered = context.Products .OrderBy(p => p.Category) .ThenByDescending(p => p.Price);
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: Projection transforms entities into custom shapes, e.g., DTOs. var projected = context.Products .Select(p => new { p.Name, p.Price }); Useful for: Reducing data load. Returning only needed fields. Mapping to custom types.
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
than one.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: (Skip, Take) Use .Skip() and .Take() for pagination: var page2 = context.Products .OrderBy(p => p.Id) .Skip(10) // Skip first 10 .Take(10) // Take next 10 .ToList();
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: Use .Skip() and .Take() for pagination: var page2 = context.Products .OrderBy(p => p.Id) .Skip(10) // Skip first 10 .Take(10) // Take next 10 .ToList();
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: Use FromSqlRaw() or FromSqlInterpolated(): var products = context.Products .FromSqlRaw("SELECT * FROM Products WHERE Price > {0}", 100) .ToList();
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: (FromSqlRaw, etc.) Use FromSqlRaw() or FromSqlInterpolated(): var products = context.Products .FromSqlRaw("SELECT * FROM Products WHERE Price > {0}", 100) .ToList();
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: Stored procedures can be called via raw SQL or FromSqlRaw: var orders = context.Orders .FromSqlRaw("EXEC GetOrdersByCustomer @CustomerId = {0}", customerId) .ToList(); For non-query SPs, use Database.ExecuteSqlRaw().
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
private static readonly Func<MyDbContext, int, Product>
_getProductById =
EF.CompileQuery((MyDbContext ctx, int id) =>
ctx.Products.First(p => p.Id == id));
// Usage:
var product = _getProductById(context, 5);Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Enable logging in DbContext options: optionsBuilder .UseSqlServer(connectionString) .LogTo(Console.WriteLine, LogLevel.Information); Or configure logging in ASP.NET Core logging pipeline. Repository Pattern & Unit of Work
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
Why use it with EF Core (pros and
cons)?
application.
Entity Framework Core Entity Framework Core Tutorial · EF Core
pplication.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Unit of Work maintains a list of operations to be committed as a single transaction. EF Core’s DbContext implements Unit of Work, tracking changes and coordinating commits (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
Entity Framework Core Entity Framework Core Tutorial · EF Core
What are the trade-offs?
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: public interface IRepository<T> where T : class { Task<T> GetByIdAsync(int id); Task<IEnumerable<T>> GetAllAsync(); Task AddAsync(T entity); void Update(T entity); void Delete(T entity); Task SaveChangesAsync(); }
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
Sample signature /
interface?
public interface IRepository<T> where T : class
Task<T> GetByIdAsync(int id);
Task<IEnumerable<T>> GetAllAsync();
Task AddAsync(T entity);
void Update(T entity);
void Delete(T entity);
Task SaveChangesAsync();
Entity Framework Core Entity Framework Core Tutorial · EF Core
public interface IUnitOfWork : IDisposable
{
IRepository<Customer> Customers { get; }
IRepository<Order> Orders { get; }
Task<int> CommitAsync();
}
repositories.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: wait _unitOfWork.CommitAsync(); wait transaction.CommitAsync(); } catch { wait transaction.RollbackAsync(); throw; }
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
using var transaction = await
_context.Database.BeginTransactionAsync();
try
// multiple repository operations
await _unitOfWork.CommitAsync();
await transaction.CommitAsync();
catch
await transaction.RollbackAsync();
throw;
Entity Framework Core Entity Framework Core Tutorial · EF Core
Performance, Best Practices, &
Advanced Features
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Practical use cases. Properties not defined in your CLR classes but tracked by EF Core. Useful for storing metadata like CreatedBy, LastModified, or foreign keys without cluttering domain models.
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: Properties not defined in your CLR classes but tracked by EF Core. Useful for storing metadata like CreatedBy, LastModified, or foreign keys without cluttering domain models.
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: When/why to use it? A filter automatically applied to all queries on an entity. Useful for soft deletes, multi-tenancy (filtering by tenant ID), or data partitioning.
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: A filter automatically applied to all queries on an entity. Useful for soft deletes, multi-tenancy (filtering by tenant ID), or data partitioning.
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: Use .AsNoTracking() for read-only queries. Avoid over-fetching: only select needed columns (Select). Use eager loading wisely (Include). Minimize round trips by batching operations. Use compiled queries for repeated query patterns.
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: EF Core batches multiple commands into a single database round trip when possible. Improves performance by reducing network overhead.
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: How does EF Core handle batch operations? EF Core batches multiple commands into a single database round trip when possible. Improves performance by reducing network overhead.
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: Use pagination (Skip, Take). Use streaming APIs like IAsyncEnumerable<T> with EF Core 5+. Avoid loading all data into memory at once.
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: EF Core doesn’t have built-in caching for query results. Use second-level caching libraries (like EFCoreSecondLevelCacheInterceptor). Use application-level caching (MemoryCache, Redis) strategically.
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: Use FromSqlRaw or ExecuteSqlRaw to execute raw SQL. Map results to entities or DTOs. Use for performance-critical or legacy operations not easily expressed in LINQ.
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
SQL Server, PostgreSQL, MySQL —
differences, limitations?
are provider-specific).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Migrations support may be limited or unavailable. May require manual scripts or provider-specific tooling. Consider NoSQL-specific approaches for schema changes.
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: Use shadow properties or explicit properties for timestamps. Override SaveChanges() to set audit fields. Use global query filters for soft delete support.
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: Implementation strategies in EF Core? Mark entities as deleted without physically removing them. Implemented using a boolean flag and global query filters to exclude “deleted” records.
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: Mark entities as deleted without physically removing them. Implemented using a boolean flag and global query filters to exclude “deleted” records.
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: EF Core can track foreign keys without them being defined in your model as properties. Useful for cleaner domain models.
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: Configure relationships explicitly. HasOne / WithMany to define navigation properties and cardinality. Offers fine control beyond Data Annotations.
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: Convert CLR types to database-compatible types and vice versa. Example: storing an enum as a string or encrypted data.
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: Complex types that don’t have their own identity and lifecycle. Useful for grouping related properties (like Address inside a Customer).
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: When to use them? Complex types that don’t have their own identity and lifecycle. Useful for grouping related properties (like Address inside a Customer).
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: Private fields in your entity class mapped by EF Core instead of public properties. Useful for encapsulating domain logic and controlling property access. Transactions, Concurrency, Security
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: EF Core automatically wraps SaveChanges() calls in a transaction. Ensures all changes are committed atomically. For multiple SaveChanges() calls, transactions need manual handling.
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
Rollback)
using var transaction = context.Database.BeginTransaction();
try {
// Perform multiple operations
context.SaveChanges();
transaction.Commit();
} catch {
transaction.Rollback();
throw;
}Entity Framework Core Entity Framework Core Tutorial · EF Core
(BeginTransaction, Commit,
Rollback)
using var transaction = context.Database.BeginTransaction();
try {
// Perform multiple operations
context.SaveChanges();
transaction.Commit();
} catch {
transaction.Rollback();
throw;
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Assumes conflicts are rare; detects conflicts when saving. Uses concurrency tokens (e.g., timestamp or row version) to detect if data was changed by another process. EF Core throws DbUpdateConcurrencyException if a conflict occurs.
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 implement it?
changed by another process.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Properties marked with [Timestamp] or configured as concurrency tokens. Stored in the database as rowversion/timestamp type or other markers. EF Core checks these tokens during updates/deletes to detect concurrent changes.
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: Catch DbUpdateConcurrencyException. Reload conflicting entity from database or merge changes. Retry operation or notify the user of conflict. Implement custom conflict resolution logic as needed. Testing, Deployment, Tools
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
databases to isolate tests.
migrations, and data persistence.
Entity Framework Core Entity Framework Core Tutorial · EF Core
database behavior exactly (no relational constraints, transactions).
Entity Framework Core Entity Framework Core Tutorial · EF Core
in tests.
mocking DbContext.
Miscellaneous / Scenario / Trick
Questions
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: dd-Migration. Maintain separate migration history tables using MigrationsHistoryTable method. Apply migrations independently for each DbContext.
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: Use separate migration folders per DbContext via the -Context option in Add-Migration. Maintain separate migration history tables using MigrationsHistoryTable method. Apply migrations independently for each DbContext.
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: Configure DbContext in Startup or Program to select provider based on environment variables or config files. Use DI to inject correct connection strings and providers. Can use conditional compilation or environment-based settings.
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
Entity Framework Core Entity Framework Core Tutorial · EF Core
Answer: Use IHostingEnvironment or config flags inside the DbContext OnModelCreating or after migration. Separate seed classes or methods per environment. Use EF Core’s HasData method or custom seed logic at runtime.
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: Use [JsonIgnore] or ReferenceLoopHandling.Ignore in JSON serialization. Use DTOs without circular refs for API responses. Carefully design navigation properties to avoid cycles or use explicit loading.
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: Define navigation property and foreign key for self-reference. Use Fluent API: .HasOne(e => e.Manager).WithMany(e => e.Subordinates).
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: lso Employee)? Define navigation property and foreign key for self-reference. Use Fluent API: .HasOne(e => e.Manager).WithMany(e => e.Subordinates).
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: Use FromSqlRaw or FromSqlInterpolated for stored procedures and views. Map views as query types or entities without keys (read-only). For insert/update via SP, call them directly from DbContext.
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: Throws InvalidOperationException or returns null since no tracking or lazy loading. Need to attach entity or explicitly load navigation properties.
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: Use context.Entry(entity).State = EntityState.Detached. Useful to avoid tracking or to simulate detached state.
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: Attach entity, then set only modified properties as Modified. Use context.Entry(entity).Property(p => p.PropertyName).IsModified = true. Useful for PATCH operations.
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: Use libraries like EFCore.BulkExtensions, Z.EntityFramework.Extensions. These provide optimized bulk operations, bypassing EF change tracking for performance.
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 does the dynamic proxy work under the hood?
Microsoft.EntityFrameworkCore.Proxies.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Microsoft.EntityFrameworkCore.Proxies.