Entity Framework Core Flashcards
6 cards from real ASP.NET Core practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 Entity Framework Core flashcards as text
What is the N+1 query problem in Entity Framework Core?
Answer: Executing one query to fetch a list then N additional queries for each item's related data
N+1 occurs when related entities are loaded via lazy loading in a loop, generating one query per item instead of a single JOIN.
Which EF Core method allows executing raw SQL and returning entity results?
Answer: FromSqlRaw()
FromSqlRaw() composes a raw SQL query that returns tracked entity instances mapped to the DbSet entity type.
What does the [Required] data annotation do on an EF Core entity property?
Answer: Marks the database column as NOT NULL and adds model validation
[Required] configures the column as NOT NULL in the schema and also participates in ASP.NET Core model validation.
Which EF Core feature automatically creates the database schema from the model without migrations?
Answer: EnsureCreated()
EnsureCreated() creates the schema if the database does not exist, but bypasses migrations — use only for testing/prototyping.
How do you configure a one-to-many relationship in EF Core Fluent API?
Answer: HasMany().WithOne()
HasMany().WithOne() defines a one-to-many relationship, with HasMany on the principal and WithOne on the dependent side.
What is the purpose of value converters in Entity Framework Core?
Answer: To convert property values between CLR types and database types during reads and writes
Value converters allow storing enums as strings, encrypting columns, or mapping custom types without changing the entity model.