Technical interview questions with detailed answers—organized by course, like Dot Net Tutorials interview sections. Original content for Toolliyo Academy.
Entity Framework Core Tutorial · CLR & types
Short answer: CLR & types is essential when working with Entity Framework Core Tutorial. Interviewers want to hear clear definitions, trade-offs, and a concise example from your experience.
Tip: Keep answers under 90 seconds unless the interviewer asks for depth. Practice aloud on Toolliyo before your mock interview.
Entity Framework Core Tutorial · ASP.NET Core
Short answer: ASP.NET Core is essential when working with Entity Framework Core Tutorial. Interviewers want to hear clear definitions, trade-offs, and a concise example from your experience.
Tip: Keep answers under 90 seconds unless the interviewer asks for depth. Practice aloud on Toolliyo before your mock interview.
Entity Framework Core Tutorial · EF Core
Short answer: EF Core is essential when working with Entity Framework Core Tutorial. Interviewers want to hear clear definitions, trade-offs, and a concise example from your experience.
Tip: Keep answers under 90 seconds unless the interviewer asks for depth. Practice aloud on Toolliyo before your mock interview.
Entity Framework Core Tutorial · Security
Short answer: Security is essential when working with Entity Framework Core Tutorial. Interviewers want to hear clear definitions, trade-offs, and a concise example from your experience.
Tip: Keep answers under 90 seconds unless the interviewer asks for depth. Practice aloud on Toolliyo before your mock interview.
Entity Framework Core Tutorial · Testing
Short answer: Testing is essential when working with Entity Framework Core Tutorial. Interviewers want to hear clear definitions, trade-offs, and a concise example from your experience.
Tip: Keep answers under 90 seconds unless the interviewer asks for depth. Practice aloud on Toolliyo before your mock interview.
Entity Framework Core Entity Framework Core Tutorial · EF Core
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.
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
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.
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
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.
Entity Framework Core Entity Framework Core Tutorial · EF Core
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.
Entity Framework Core Entity Framework Core Tutorial · EF Core
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.
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
Entity Framework Core Entity Framework Core Tutorial · EF Core
What is “LINQ to Entities”?
executed in the database.
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
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
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
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
Use the CLI or Package Manager Console:
dotnet ef dbcontext scaffold "YourConnectionString"
Microsoft.EntityFrameworkCore.SqlServer -o Models
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
(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
(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.
Entity Framework Core Entity Framework Core Tutorial · EF Core
by EF Core.
[YourDbContext]ModelSnapshot.cs.
Entity Framework Core Entity Framework Core Tutorial · EF Core
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
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
Use the HasData() method in OnModelCreating():
modelBuilder.Entity<User>().HasData(
new User { Id = 1, Name = "Admin" }
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
Down() methods.
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
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
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
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
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
You can disable tracking by default for a specific DbContext using:
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTrac
king);
Or per-query using .AsNoTracking().
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
A 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
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
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 });
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
A 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
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
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
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
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
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.
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
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
var filtered = context.Products.Where(p => p.Price > 100);
var ordered = context.Products
.OrderBy(p => p.Category)
.ThenByDescending(p => p.Price);
Entity Framework Core Entity Framework Core Tutorial · EF Core
var projected = context.Products
.Select(p => new { p.Name, p.Price });
Entity Framework Core Entity Framework Core Tutorial · EF Core
than one.
Entity Framework Core Entity Framework Core Tutorial · EF Core
(Skip, Take)
var page2 = context.Products
.OrderBy(p => p.Id)
.Skip(10) // Skip first 10
.Take(10) // Take next 10
.ToList();
Entity Framework Core Entity Framework Core Tutorial · EF Core
(FromSqlRaw, etc.)
var products = context.Products
.FromSqlRaw("SELECT * FROM Products WHERE Price > {0}", 100)
.ToList();
Entity Framework Core Entity Framework Core Tutorial · EF Core
var orders = context.Orders
.FromSqlRaw("EXEC GetOrdersByCustomer @CustomerId = {0}",
customerId)
.ToList();
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
optionsBuilder
.UseSqlServer(connectionString)
.LogTo(Console.WriteLine, LogLevel.Information);
Repository Pattern & Unit of Work
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
How does DbContext relate to Unit
of Work?
commits (SaveChanges()).
Entity Framework Core Entity Framework Core Tutorial · EF Core
What are the trade-offs?
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
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
Practical use cases.
cluttering domain models.
Entity Framework Core Entity Framework Core Tutorial · EF Core
When/why to use it?
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
How does EF Core handle batch operations?
possible.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
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
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
Implementation strategies in EF Core?
records.
Entity Framework Core Entity Framework Core Tutorial · EF Core
properties.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
When to use them?
Entity Framework Core Entity Framework Core Tutorial · EF Core
Transactions, Concurrency, Security
Entity Framework Core Entity Framework Core Tutorial · EF Core
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
How to implement it?
changed by another process.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
Testing, Deployment, Tools
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
Add-Migration.
method.
Entity Framework Core Entity Framework Core Tutorial · EF Core
environment variables or config files.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
OnModelCreating or after migration.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
e.Subordinates).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
Entity Framework Core Entity Framework Core Tutorial · EF Core
p.PropertyName).IsModified = true.
Entity Framework Core Entity Framework Core Tutorial · EF Core
performance.
Entity Framework Core Entity Framework Core Tutorial · EF Core
How does the dynamic proxy work under the hood?
Microsoft.EntityFrameworkCore.Proxies.