.NET

Entity Framework Core

DbContext, DbSet, LINQ queries, tracking, relationships, migrations, best practices

25 면접 질문·
Mid-Level
1

What is a DbContext in Entity Framework Core?

답변

DbContext is the central class in Entity Framework Core that represents a session with the database. It allows configuring the model, performing LINQ queries on entities, and persisting changes through SaveChanges. Each DbContext instance maintains an entity cache and change tracking to optimize persistence operations.

2

What is the role of a DbSet<T> in Entity Framework Core?

답변

DbSet<T> represents a collection of entities of a specific type in the database context. It exposes CRUD operations (Create, Read, Update, Delete) and serves as the entry point for LINQ queries. Each DbSet typically corresponds to a table in the database and allows adding, removing, or querying entities of that type.

3

What is the difference between Add and AddRange in Entity Framework Core?

답변

Add adds a single entity to the context while AddRange adds multiple entities in a single operation. For performance reasons, using AddRange is preferred when adding multiple entities as it reduces the number of change detection operations. Both methods mark entities with the Added state until SaveChanges is called.

4

What does the SaveChanges method do in Entity Framework Core?

5

When to use the ChangeTracker in Entity Framework Core?

+22 면접 질문

다음 면접을 위해 .NET을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기