LearnThatStack Ace your next interview
Backend Development

Entity Framework Core.

Start free Change topic Change
Practice · Questions

All questions

Showing of 54
Beginner 12
01

What are the main approaches to using Entity Framework Core?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

EF Core supports two main approaches, Code First and Database First. They differ in which side defines the model, your C# classes or an existing database.

With Code First, you write the entity classes and a DbContext first. Migrations then create the database and change its schema as the classes change. This suits new projects where the team has full control over the data model.

With Database First, you start from an existing database. The Scaffold-DbContext command, or dotnet ef dbcontext scaffold on the CLI, generates the DbContext and entity classes from its tables. This suits existing databases and database-driven development, where the schema is designed first.

Model First belongs to EF6, not EF Core. EF Core has no visual designer and no EDMX model file, so you model in code or start from the database.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What is an Entity in Entity Framework Core?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

An entity is a C# class that EF Core maps to a database table, and each instance of it is one row in that 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; }
}

By convention, a property named Id or <TypeName>Id becomes the primary key. The other properties map to columns, and Category is a navigation property that points to a related entity.

An entity must be a class, not a struct, and it should have a key. EF Core does not need a parameterless constructor, because it can call a constructor whose parameters match mapped properties. It also maps properties with private setters.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What is DbContext and what is its role in Entity Framework Core?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

DbContext is the main class you use to work with the database in EF Core. It represents a session with the database and implements the Unit of Work pattern. It collects your changes and writes them together.

It manages the database connection, translates LINQ queries into SQL, and tracks changes to the entities it manages. Each tracked entity has a state such as Added, Modified or Deleted. When you call SaveChanges, the context writes those changes in a transaction.

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");
    }
}

A DbContext is short-lived and not thread-safe, so use one instance per unit of work, such as one web request.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What is DbSet and how is it used?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

DbSet<T> represents the collection of all entities of one type, and it usually maps to one table. You declare one per entity type on your DbContext, and it is the starting point for queries and changes.

A LINQ query over a DbSet is translated to SQL and runs when you enumerate it. Add, Update and Remove do not touch the database. They set the entity's state in the change tracker, and SaveChanges writes it. The Local property returns the entities the context already tracks, without a new query.

// 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();
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What is the difference between DbContext.SaveChanges() and DbContext.SaveChangesAsync()?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

SaveChanges() blocks the calling thread until the database finishes, while SaveChangesAsync() frees the thread while it waits. The async version returns a Task<int> that you await. Otherwise they do the same work. Both write the tracked changes in one transaction and return the number of entries written.

// Synchronous
int changesCount = context.SaveChanges();
// Asynchronous
changesCount = await context.SaveChangesAsync();

In a web app, a blocked thread cannot serve other requests, so async gives better scalability under high traffic. In a desktop app it keeps the UI responsive. Async does not make a single save faster.

Always await the call before you use the context again. EF Core does not support two operations running at the same time on one DbContext.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What are Data Annotations and how are they used in Entity Framework Core?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Data annotations are attributes you put on entity classes and properties to configure the model. EF Core reads them when it builds the model, so they shape the schema that migrations create.

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; }
}
  • [Key] marks the primary key
  • [Required] makes Name a non-null column
  • [MaxLength(100)] sets its length
  • [Column(TypeName = ...)] picks the SQL type
  • [ForeignKey] names the foreign key behind a navigation
  • [NotMapped] leaves a property out of the table

Other common ones are [DatabaseGenerated], [Table] and [InverseProperty]. [Required], [MaxLength] and [Range] also drive validation in ASP.NET Core.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

What are Migrations in Entity Framework Core and why are they important?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Migrations let you change the database schema step by step to match your entity model, without dropping the database and losing its data. Each migration is a C# class whose Up method applies a change and whose Down method reverts it.

They matter for four reasons.

  • The schema history lives in source control next to the code.
  • Teammates share schema changes by pulling and applying each other's migrations.
  • The same migrations bring development, test and production databases to the same version.
  • You can roll back by updating to an earlier migration.
# Add migration
dotnet ef migrations add InitialCreate
# Update database
dotnet ef database update
# Remove last migration
dotnet ef migrations remove
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

How do you create and apply migrations?

Part of Pro Visual
09

What are the different types of relationships in Entity Framework Core?

Part of Pro
10

How do you configure One-to-Many relationships?

Part of Pro
11

What are Navigation Properties and how do they work?

Part of Pro
12

What is the difference between First(), FirstOrDefault(), Single(), and SingleOrDefault()?

Part of Pro
Intermediate 27
13

Explain the different ways to configure DbContext.

Part of Pro
14

What is Fluent API and when would you use it over Data Annotations?

Part of Pro
15

How do you scaffold an existing database using Entity Framework Core?

Part of Pro
16

How can you customize migration generation?

Part of Pro
17

What happens when you have migration conflicts in a team environment?

Part of Pro Visual
18

How do you configure Many-to-Many relationships in EF Core 5+?

Part of Pro
19

How do you handle self-referencing relationships?

Part of Pro
20

What's the difference between IQueryable and IEnumerable in EF Core context?

Part of Pro Visual
21

How do you use Include() for eager loading and what are its limitations?

Part of Pro
22

How do you write raw SQL queries in Entity Framework Core?

Part of Pro
23

What is Change Tracking in Entity Framework Core and how does it work?

Part of Pro Visual
24

How do you disable Change Tracking for read-only scenarios?

Part of Pro Visual
25

What is the difference between Update() and modifying properties directly?

Part of Pro Visual
26

How do you detect property changes in Entity Framework Core?

Part of Pro
27

How do you configure entity properties using Fluent API?

Part of Pro
28

How do you configure indexes in Entity Framework Core?

Part of Pro
29

How do you implement paging efficiently in Entity Framework Core?

Part of Pro Visual
30

How do you work with database transactions in Entity Framework Core?

Part of Pro
31

How do you handle the "Cannot access a disposed object" error?

Part of Pro Visual
32

How do you implement Repository Pattern with Entity Framework Core?

Part of Pro
33

How do you implement database seeding in Entity Framework Core?

Part of Pro
34

What is the difference between eager, explicit and lazy loading in EF Core?

Part of Pro Visual
35

What are ExecuteUpdate and ExecuteDelete, and how do they differ from SaveChanges?

Part of Pro
36

How does EF Core compare to Dapper, and when would you choose each?

Part of Pro
37

What are Global Query Filters and how do you implement them?

Part of Pro
38

What are Value Converters and how do you use them?

Part of Pro Visual
39

What are Shadow Properties and how do you use them?

Part of Pro
Expert 15
40

What are some common performance issues in Entity Framework Core and how to avoid them?

Part of Pro
41

What are compiled queries and when should you use them?

Part of Pro
42

How do you use Split Queries to optimize performance?

Part of Pro Visual
43

How do you handle concurrency conflicts in Entity Framework Core?

Part of Pro Visual
44

What is the difference between pessimistic and optimistic locking?

Part of Pro Visual
45

What are Owned Types and when would you use them?

Part of Pro
46

How do you implement Table Splitting in Entity Framework Core?

Part of Pro
47

How do you implement Soft Delete using Global Query Filters?

Part of Pro
48

What are Keyless Entity Types and when would you use them?

Part of Pro
49

What are some Entity Framework Core best practices for production applications?

Part of Pro
50

How do you handle complex business logic with Entity Framework Core?

Part of Pro
51

What are some strategies for testing applications that use Entity Framework Core?

Part of Pro
52

How do you implement multi-tenancy with Entity Framework Core?

Part of Pro Visual
53

How do you implement temporal tables (system-versioned tables) with EF Core?

Part of Pro Visual
54

How do you handle complex inheritance scenarios in Entity Framework Core?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for Entity Framework Core? Send them this set.
Quick recap

Entity Framework Core in pictures.

A quick recap of Entity Framework Core in 33 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 30 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

47 of 54 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.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git