Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: 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; } [Fore…
Short answer: In EF Core 5.0+, you can define many-to-many relationships without an explicit join entity: public class Student Example code { public ICollection<Course> Courses { get; set; } } public class Course {…
Short answer: 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. { Example code public int StudentId { g…
Short answer: 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. 🛠…
Short answer: nnotations & 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; } [ForeignKey…
Short answer: How to define them via annotations & Fluent API? Explain a bit more Primary Key (PK): Unique identifier of a record. Foreign Key (FK): A field that references a PK in another table. Data Annotations: [K…
Short 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 => ne…
Short answer: How to define composite keys in EF Core? A 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 API: modelBuilder.Ent…
Short answer: 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) .O…
Short answer: A shadow property is a property not defined in the .NET class but exists in the EF model. Example code modelBuilder.Entity<Post>() .HasOne<Blog>() .WithMany() .HasForeignKey("BlogId");…
Short answer: 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 F…
Short answer: 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();…
Short answer: 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.B…
Short answer: 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 Enable in…
Short answer: 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: Mic…
Short answer: Explicit loading means loading related data manually, after the main entity is loaded. Explain a bit more Use when: You need full control over what and when to load You don’t want automatic lazy loading var…
Short answer: When & how to use it? Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy load…
Short answer: The N+1 problem occurs when: 1 query loads N parent entities N additional queries load related entities (1 per parent) Example (lazy loading): foreach (var blog in context.Blogs) { Console.WriteLine(blog.Ow…
Short answer: How can lazy loading lead to it? The N+1 problem occurs when: 1 query loads N parent entities N additional queries load related entities (1 per parent) Example (lazy loading): foreach (var blog in context.B…
Short answer: 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 co…
Short 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 vir…
Short 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 the…
Short answer: By default, EF Core uses no automatic loading — it doesn’t lazy-load or eager-load relationships unless you: Use .Include() for eager loading Enable lazy loading proxies Use .Load() for explicit loading Thi…
Short answer: 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…
Short answer: 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 expre…
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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; } } A foreign key exists in the many-side entity (Post). EF infers this relationship from navigation + FK.
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; }
} A foreign key exists in the many-side entity (Post). EF infers this relationship from navigation + FK.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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. {
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.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: nnotations & 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; } [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);…
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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; } [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);
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short 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 }); composite key is a primary key made of multiple columns.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: How to define composite keys in EF Core? A 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 API: modelBuilder.Entity<OrderDetail>() .HasKey(od => new { od.OrderId, od.ProductId });
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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: Cascade Restrict SetNull NoAction EF Core defaults to Cascade for required relationships.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: A shadow property is a property not defined in the .NET class but exists in the EF model.
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.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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 BlogId) → required Entity Framework Core – Lazy vs Eager vs Explicit Loading
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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.
Loading orders with items uses .Include(o => o.Items). Without Include, listing 50 orders can trigger 50 extra queries (N+1).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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…
Loading orders with items uses .Include(o => o.Items). Without Include, listing 50 orders can trigger 50 extra queries (N+1).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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 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…
Loading orders with items uses .Include(o => o.Items). Without Include, listing 50 orders can trigger 50 extra queries (N+1).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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.
Loading orders with items uses .Include(o => o.Items). Without Include, listing 50 orders can trigger 50 extra queries (N+1).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: Explicit loading means loading related data manually, after the main entity is loaded.
Use when: You need full control over what and when to load You don’t want automatic lazy loading 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 Explicit loading means loading related data manually, after the main entity is loaded. Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy loading
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 Explicit loading means loading related data manually, after the main entity is loaded. Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy loading 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 Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy loading 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
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: When & how to use it? Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy loading
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
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: The N+1 problem occurs when: 1 query loads N parent entities N additional queries load related entities (1 per parent) 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. The N+1 problem occurs when: 1 query loads N parent entities N additional queries load related entities (1 per parent) 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.
Loading orders with items uses .Include(o => o.Items). Without Include, listing 50 orders can trigger 50 extra queries (N+1).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: How can lazy loading lead to it? The N+1 problem occurs when: 1 query loads N parent entities N additional queries load related entities (1 per parent) 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…
Loading orders with items uses .Include(o => o.Items). Without Include, listing 50 orders can trigger 50 extra queries (N+1).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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
Short 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. 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. 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. 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.
Loading orders with items uses .Include(o => o.Items). Without Include, listing 50 orders can trigger 50 extra queries (N+1).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short 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.
Loading orders with items uses .Include(o => o.Items). Without Include, listing 50 orders can trigger 50 extra queries (N+1).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: By default, EF Core uses no automatic loading — it doesn’t lazy-load or eager-load relationships unless you: Use .Include() for eager loading Enable lazy loading proxies Use .Load() for explicit loading This default avoids unintended queries and promotes performance control. EF Core LINQ Queries & Querying
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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 runtime exceptions. Client-side evaluation may occur, which can hurt performance. Use .AsEnumerable() to switch to client-side processing intentionally.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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 be translated and cause runtime exceptions. Client-side evaluation may occur, which can hurt performance. Use .AsEnumerable() to switch to client-side processing intentionally.
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.