All questions
Showing of 52What are the main approaches to using Entity Framework Core?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
EF Core supports three main approaches:
- Code First: Define entity classes first, then generate database schema
- Start with C# classes (entities)
- Use migrations to create and update database
- Good for new projects with full control over data model
- Database First: Start with existing database, generate entity classes
- Use
Scaffold-DbContextcommand - Generates DbContext and entity classes from existing database
- Good for existing databases or database-driven development
- Use
- Model First: Design model using visual designer (less common in EF Core)
- Primarily supported through external tools
- Not as prominent as in EF6
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is an Entity in Entity Framework Core?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
An Entity is a class that represents a table in the database. Each instance of an entity corresponds to a row in the table.
public class Product
{
public int Id { get; set; } // Primary key
public string Name { get; set; }
public decimal Price { get; set; }
public int CategoryId { get; set; }
// Navigation property
public Category Category { get; set; }
}
Requirements for an entity:
- Must be a reference type (class)
- Must have a parameterless constructor
- Should have a primary key property
- Properties must have public getters and setters (or protected setters)
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is DbContext and what is its role in Entity Framework Core?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
DbContext is the primary class responsible for interacting with the database. It represents a session with the database and acts as a Unit of Work pattern implementation.
Key responsibilities:
- Database connection management: Manages database connections
- Change tracking: Tracks changes to entities
- Query execution: Translates LINQ queries to SQL
- Transaction management: Handles database transactions
- Entity lifecycle: Manages entity states (Added, Modified, Deleted, etc.)
public class ApplicationDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("connection-string");
}
}
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is DbSet and how is it used?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
DbSet<T> represents a collection of entities of a specific type that can be queried from the database. It provides an abstraction over database tables.
Key features:
- Querying: Supports LINQ queries
- CRUD operations: Add, Remove, Update operations
- Change tracking: Tracks entity states
- Local view: Access to locally tracked entities
// Querying
var products = context.Products.Where(p => p.Price > 100).ToList();
// Adding
context.Products.Add(new Product { Name = "New Product" });
// Removing
context.Products.Remove(product);
// Local entities
var localProducts = context.Products.Local.ToList();
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between DbContext.SaveChanges() and DbContext.SaveChangesAsync()?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
- SaveChanges(): Synchronous method that blocks the calling thread until database operations complete
- SaveChangesAsync(): Asynchronous method that doesn't block the calling thread, returns
Task<int>
// Synchronous
int changesCount = context.SaveChanges();
// Asynchronous
int changesCount = await context.SaveChangesAsync();
Benefits of async:
- Better scalability in web applications
- Doesn't block threads during I/O operations
- Improves application responsiveness
- Essential for high-traffic applications
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are Data Annotations and how are they used in Entity Framework Core?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Data Annotations are attributes applied to entity classes and properties to configure the model and validation rules.
Common annotations:
public class Product
{
[Key]
public int ProductId { get; set; }
[Required]
[MaxLength(100)]
public string Name { get; set; }
[Column(TypeName = "decimal(18,2)")]
public decimal Price { get; set; }
[ForeignKey("CategoryId")]
public Category Category { get; set; }
[NotMapped]
public string DisplayName { get; set; }
}
Categories:
- Key attributes:
[Key],[DatabaseGenerated] - Validation:
[Required],[MaxLength],[Range] - Schema:
[Table],[Column],[NotMapped] - Relationships:
[ForeignKey],[InverseProperty]
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are Migrations in Entity Framework Core and why are they important?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Migrations are a way to incrementally update the database schema to keep it in sync with the entity model while preserving existing data.
Benefits:
- Version control: Track database schema changes
- Team collaboration: Share schema changes across team
- Deployment: Apply changes to different environments
- Rollback: Undo changes if needed
- Data preservation: Update schema without losing data
# Add migration
dotnet ef migrations add InitialCreate
# Update database
dotnet ef database update
# Remove last migration
dotnet ef migrations remove
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you create and apply migrations?
What are the different types of relationships in Entity Framework Core?
How do you configure One-to-Many relationships?
What are Navigation Properties and how do they work?
What is the difference between First(), FirstOrDefault(), Single(), and SingleOrDefault()?
Explain the different ways to configure DbContext.
What is Fluent API and when would you use it over Data Annotations?
How do you scaffold an existing database using Entity Framework Core?
How can you customize migration generation?
What happens when you have migration conflicts in a team environment?
How do you configure Many-to-Many relationships in EF Core 5+?
How do you handle self-referencing relationships?
What's the difference between IQueryable and IEnumerable in EF Core context?
How do you use Include() for eager loading and what are its limitations?
How do you write raw SQL queries in Entity Framework Core?
What is Change Tracking in Entity Framework Core and how does it work?
How do you disable Change Tracking for read-only scenarios?
What is the difference between Update() and modifying properties directly?
How do you detect property changes in Entity Framework Core?
How do you configure entity properties using Fluent API?
How do you configure indexes in Entity Framework Core?
How do you implement paging efficiently in Entity Framework Core?
How do you work with database transactions in Entity Framework Core?
How do you handle the "Cannot access a disposed object" error?
How do you implement Repository Pattern with Entity Framework Core?
How do you implement database seeding in Entity Framework Core?
What are Global Query Filters and how do you implement them?
What are Value Converters and how do you use them?
What are some common performance issues in Entity Framework Core and how to avoid them?
What is Compiled Queries and when should you use them?
How do you use Split Queries to optimize performance?
How do you handle concurrency conflicts in Entity Framework Core?
What is the difference between pessimistic and optimistic locking?
What are Owned Types and when would you use them?
How do you implement Table Splitting in Entity Framework Core?
What are Shadow Properties and how do you use them?
How do you implement Soft Delete using Global Query Filters?
What are Keyless Entity Types and when would you use them?
What are some Entity Framework Core best practices for production applications?
What are the common causes of poor performance in EF Core applications?
How do you handle complex business logic with Entity Framework Core?
What are some strategies for testing applications that use Entity Framework Core?
How do you implement multi-tenancy with Entity Framework Core?
How do you implement temporal tables (system-versioned tables) with EF Core?
How do you handle complex inheritance scenarios in Entity Framework Core?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Entity Framework Core cheatsheet
- Core Concepts01
- DbContext & Configuration02
- Entity Configuration03
- CRUD Operations04
- Querying Data05
- Relationships06
- Migrations07
- Performance Optimization08
- Advanced Features09
- Common Interview Patterns10
- Best Practices & Performance Tips11
- Quick Reference12
- + 6 more inside
45 of 52 Entity Framework Core answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.