Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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…
Answer: You can disable tracking by default for a specific DbContext using: optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTrac king); Or per-query using .AsNoTracking(). What interviewers expect A clear…
Use the Entry() method: context.Entry(entity).State = EntityState.Modified; context.Entry(entity).State = EntityState.Detached; This is helpful when: You’re updating data without reloading it Working with disconnected sc…
What is optimistic concurrency vs pessimistic concurrency? Optimistic concurrency: Assumes that conflicts are rare. EF checks for changes before saving using concurrency tokens. Pessimistic concurrency: Locks records in…
EF Core supports the standard types of relationships: One-to-One (1:1) – One entity has one related entity. One-to-Many (1:N) – One entity relates to many others. Many-to-Many (M:N) – Many entities relate to many others.…
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, Fore…
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…
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<Stud…
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 StudentC…
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…
How to define them via annotations & Fluent API? Primary Key (PK): Unique identifier of a record. Foreign Key (FK): A field that references a PK in another table. Data Annotations: [Key] public int Id { get; set; } […
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 n…
In Fluent API: Required: .HasRequired(p => p.Blog) Optional: .HasOne(p => p.Blog) .WithMany() .IsRequired(false); EF infers: Reference type (e.g., Blog) → optional by default Non-nullable value type FK (e.g., int B…
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…
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.…
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 virt…
EF Core translates LINQ queries into SQL using expression trees. Only supported LINQ operators and expressions can be translated. Limitations: Certain C# methods or complex expressions cannot be translated and cause runt…
What limitations are there? EF Core translates LINQ queries into SQL using expression trees. Only supported LINQ operators and expressions can be translated. Limitations: Certain C# methods or complex expressions cannot…
IQueryable<T>: Represents a query against the data source. Query is translated to SQL and executed on the database. Supports deferred execution. IEnumerable<T>: Represents an in-memory collection. LINQ operat…
Inner join example: var query = from c in context.Customers join o in context.Orders on c.Id equals o.CustomerId select new { c.Name, o.OrderDate }; Left join (using DefaultIfEmpty()): var query = from c in context.Custo…
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…
Answer: Filtering: var filtered = context.Products.Where(p =&gt; p.Price &gt; 100); Ordering: var ordered = context.Products .OrderBy(p =&gt; p.Category) .ThenByDescending(p =&gt; p.Price); What interview…
First(): Returns the first element, throws if none found. FirstOrDefault(): Returns first element or default (null) if none. Single(): Returns the single element, throws if zero or more than one. SingleOrDefault(): Retur…
Answer: Use .Skip() and .Take() for pagination: var page2 = context.Products .OrderBy(p =&gt; p.Id) .Skip(10) // Skip first 10 .Take(10) // Take next 10 .ToList(); What interviewers expect A clear definition tied to…
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
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
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
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
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
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
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: 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: 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
cause runtime exceptions.
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
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
than one.
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.