Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short 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 Datab…
Short answer: Precompile frequently used queries to improve performance: private static readonly Func<MyDbContext, int, Product> _getProductById = EF.CompileQuery((MyDbContext ctx, int id) => ctx.Products.First(…
Short 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…
Short answer: Generic repository provides CRUD for all entity types. Advantages: Reusable and reduces boilerplate. Simple for basic CRUD. Disadvantages: Can become too generic, losing flexibility for complex queries. May…
Short answer: What are the trade-offs? Generic repository provides CRUD for all entity types. Advantages: Reusable and reduces boilerplate. Simple for basic CRUD. Disadvantages: Can become too generic, losing flexibility…
Short 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 enti…
Short answer: 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…
Short answer: public interface IUnitOfWork : IDisposable { IRepository<Customer> Customers { get; } IRepository<Order> Orders { get; } Task<int> CommitAsync(); } Implementation typically injects a singl…
Short answer: wait _unitOfWork.CommitAsync(); wait transaction.CommitAsync(); } catch { wait transaction.RollbackAsync(); throw; } wait _unitOfWork.CommitAsync(); wait transaction.CommitAsync(); } catch { wait transactio…
Short answer: Use DbContext transaction or IDbContextTransaction: using var transaction = await _context.Database.BeginTransactionAsync(); try { // multiple repository operations await _unitOfWork.CommitAsync(); Example…
Short answer: Mocking DbContext using frameworks like Moq (complex). Use InMemoryDatabase provider from EF Core for integration-like tests. Abstract dependencies and inject mocked interfaces for isolation. Performance, B…
Short 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. Real-world example (ShopNest) S…
Short 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. Say this i…
Short 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…
Short answer: Use pagination (Skip, Take). Use streaming APIs like IAsyncEnumerable<T> with EF Core 5+. Avoid loading all data into memory at once. Real-world example (ShopNest) ShopNest’s order service uses EF Cor…
Short 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. Real-w…
Short 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. Real-world example (ShopNest) ShopNest’s…
Short answer: SQL Server, PostgreSQL, MySQL — differences, limitations? Providers abstract database-specific implementations. Each supports different features & SQL dialects. Some features may not be supported on all…
Short answer: Migrations support may be limited or unavailable. May require manual scripts or provider-specific tooling. Consider NoSQL-specific approaches for schema changes. Real-world example (ShopNest) When ShopNest…
Short answer: Use shadow properties or explicit properties for timestamps. Override SaveChanges() to set audit fields. Use global query filters for soft delete support. Real-world example (ShopNest) ShopNest’s order serv…
Short answer: EF Core can track foreign keys without them being defined in your model as properties. Useful for cleaner domain models. Real-world example (ShopNest) ShopNest’s order service uses EF Core to save an Order…
Short answer: Configure relationships explicitly. HasOne / WithMany to define navigation properties and cardinality. Offers fine control beyond Data Annotations. Real-world example (ShopNest) ShopNest’s order service use…
Short answer: Convert CLR types to database-compatible types and vice versa. Example: storing an enum as a string or encrypted data. Real-world example (ShopNest) ShopNest’s order service uses EF Core to save an Order an…
Short answer: Complex types that don’t have their own identity and lifecycle. Useful for grouping related properties (like Address inside a Customer). Real-world example (ShopNest) ShopNest’s order service uses EF Core t…
Short 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). Real-world example (ShopNest) ShopNest’s order serv…
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short 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().
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: Precompile frequently used queries to improve performance: 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);
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: 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
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: Generic repository provides CRUD for all entity types. Advantages: Reusable and reduces boilerplate. Simple for basic CRUD. Disadvantages: Can become too generic, losing flexibility for complex queries. May leak EF Core specifics or cause over-abstraction. Sometimes custom repositories per aggregate are better.
ShopNest registers AppDbContext as scoped. One HTTP request = one context. Never inject it as a singleton.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: What are the trade-offs? Generic repository provides CRUD for all entity types. Advantages: Reusable and reduces boilerplate. Simple for basic CRUD. Disadvantages: Can become too generic, losing flexibility for complex queries. May leak EF Core specifics or cause over-abstraction. Sometimes custom repositories per aggregate are better.
ShopNest registers AppDbContext as scoped. One HTTP request = one context. Never inject it as a singleton.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short 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(); } 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(); } 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(); } 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(); }
ShopNest registers AppDbContext as scoped. One HTTP request = one context. Never inject it as a singleton.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: 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(); }
ShopNest registers AppDbContext as scoped. One HTTP request = one context. Never inject it as a singleton.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: public interface IUnitOfWork : IDisposable { IRepository<Customer> Customers { get; } IRepository<Order> Orders { get; } Task<int> CommitAsync(); } Implementation typically injects a single DbContext instance shared across repositories. CommitAsync() calls DbContext.SaveChangesAsync().
public interface IUnitOfWork : IDisposable
{ IRepository<Customer> Customers { get; } IRepository<Order> Orders { get; } Task<int> CommitAsync(); } Implementation typically injects a single DbContext instance shared across repositories. CommitAsync() calls DbContext.SaveChangesAsync().
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: wait _unitOfWork.CommitAsync(); wait transaction.CommitAsync(); } catch { wait transaction.RollbackAsync(); throw; } wait _unitOfWork.CommitAsync(); wait transaction.CommitAsync(); } catch { wait transaction.RollbackAsync(); throw; } wait _unitOfWork.CommitAsync(); wait transaction.CommitAsync(); } catch { wait transaction.RollbackAsync(); throw; } wait… _unitOfWork.CommitAsync(); wait transaction.CommitAsync(); }…
catch { wait transaction.RollbackAsync(); throw; }
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: Use DbContext transaction or IDbContextTransaction: using var transaction = await _context.Database.BeginTransactionAsync(); try { // multiple repository operations await _unitOfWork.CommitAsync();
await transaction.CommitAsync();
} catch {
await transaction.RollbackAsync(); throw; }
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: Mocking DbContext using frameworks like Moq (complex). Use InMemoryDatabase provider from EF Core for integration-like tests. Abstract dependencies and inject mocked interfaces for isolation. Performance, Best Practices, & Advanced Features
ShopNest registers AppDbContext as scoped. One HTTP request = one context. Never inject it as a singleton.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short 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.
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: 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.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short 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.
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: Use pagination (Skip, Take). Use streaming APIs like IAsyncEnumerable<T> with EF Core 5+. Avoid loading all data into memory at once.
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 doesn’t have built-in caching for query results. Use second-level caching libraries (like EFCoreSecondLevelCacheInterceptor). Use application-level caching (MemoryCache, Redis) strategically.
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: 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.
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: SQL Server, PostgreSQL, MySQL — differences, limitations? Providers abstract database-specific implementations. Each supports different features & SQL dialects. Some features may not be supported on all providers (e.g., some EF Core features are provider-specific).
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: Migrations support may be limited or unavailable. May require manual scripts or provider-specific tooling. Consider NoSQL-specific approaches for schema changes.
When ShopNest adds a DiscountCode column, you create a migration, review the SQL, then apply it on staging before production.
Entity Framework Core Entity Framework Core Tutorial · EF Core
Short answer: Use shadow properties or explicit properties for timestamps. Override SaveChanges() to set audit fields. Use global query filters for soft delete support.
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 can track foreign keys without them being defined in your model as properties. Useful for cleaner domain models.
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: Configure relationships explicitly. HasOne / WithMany to define navigation properties and cardinality. Offers fine control beyond Data Annotations.
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: Convert CLR types to database-compatible types and vice versa. Example: storing an enum as a string or encrypted data.
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: Complex types that don’t have their own identity and lifecycle. Useful for grouping related properties (like Address inside a Customer).
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 to use them? Complex types that don’t have their own identity and lifecycle. Useful for grouping related properties (like Address inside a Customer).
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.