Entity Framework Core Interview

Relationships, Navigation Properties & Loading Data

Entity Framework Core interview questions covering relationships, navigation properties, foreign keys, eager loading, explicit loading, lazy loading and related data.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
26
JuniorBeginner

What is a relationship in EF Core?

A relationship describes how two entity types are associated. EF Core represents relationships using primary keys, foreign keys, and navigation properties.

27
JuniorBeginner

What is a navigation property in EF Core?

A navigation property represents a relationship between entities in the object model. A reference navigation points to one related entity, while a collection navigation points to multiple related entities.

28
JuniorBeginner

What is a foreign key property in EF Core?

A foreign key property stores the key value that links a dependent entity to its principal entity. EF Core can often discover foreign keys by conventions such as CustomerId for a Customer navigation.

29
JuniorBeginner

What is a one-to-many relationship in EF Core?

A one-to-many relationship means one principal entity can be associated with many dependent entities, while each dependent is associated with one principal.

30
JuniorBeginner

What is a one-to-one relationship in EF Core?

A one-to-one relationship means one entity is associated with at most one related entity on the other side.

31
JuniorBeginner

What is a many-to-many relationship in EF Core?

A many-to-many relationship means each entity on either side can relate to multiple entities on the other side. For example, a Student can take many Courses and a Course can have many Students.

32
JuniorBeginner

When should you use an explicit join entity for a many-to-many relationship?

Use an explicit join entity when the relationship has its own data or behavior. Examples include enrollment date between Student and Course, quantity between Order and Product, or assigned role between User and Project.

33
JuniorBeginner

What are principal and dependent entities in EF Core relationships?

The principal entity is the entity whose key is referenced by the relationship. The dependent entity contains the foreign key that points to the principal.

34
JuniorBeginner

What is a required relationship in EF Core?

A required relationship means the dependent must be associated with a principal. For a relational database, the foreign-key column is normally non-nullable.

35
JuniorBeginner

What is an optional relationship in EF Core?

An optional relationship allows the dependent entity to exist without an associated principal. The foreign-key property is normally nullable.

36
JuniorBeginner

How do you configure relationships with the Fluent API?

Relationship configuration typically starts with HasOne or HasMany and continues with WithOne or WithMany. HasForeignKey can explicitly identify the dependent foreign-key property.

37
JuniorBeginner

What is relationship fix-up in EF Core?

Relationship fix-up is EF Core's process of keeping navigation properties and foreign-key values synchronized for tracked entities.

38
JuniorBeginner

What is eager loading in EF Core?

Eager loading retrieves related data as part of the query by using Include and ThenInclude.

39
JuniorBeginner

What are Include and ThenInclude?

Include specifies a related navigation to load with the main query. ThenInclude continues from an included navigation to load another level of related data.

40
JuniorBeginner

What is explicit loading in EF Core?

Explicit loading loads related data for an entity after that entity has already been queried and is being tracked.

41
JuniorBeginner

What is lazy loading in EF Core?

Lazy loading retrieves related data automatically when a navigation property is accessed. EF Core can support lazy loading through proxies or other configured mechanisms.

42
JuniorBeginner

What is the N+1 query problem?

The N+1 problem occurs when one query loads a set of parent records and then an additional query is executed for each parent to load related data.

43
JuniorBeginner

What is projection in EF Core?

Projection uses Select to retrieve only the columns and related values needed by the application instead of materializing complete entity graphs.

44
JuniorBeginner

What is a split query in EF Core?

A split query loads certain included collection relationships using multiple SQL queries instead of one large joined query.

45
JuniorBeginner

What is a single query in EF Core?

A single query retrieves an included entity graph through one SQL query, typically using joins. This avoids the multiple round trips associated with split queries.

46
JuniorBeginner

What is cascade delete in EF Core?

Cascade delete means deleting a principal can automatically cause related dependent rows to be deleted when the relationship and database behavior are configured for cascading.

47
JuniorBeginner

What is DeleteBehavior in EF Core?

DeleteBehavior controls how EF Core and the database handle a relationship when a principal entity is deleted or a relationship is severed.

48
JuniorBeginner

What are shadow properties in EF Core?

A shadow property exists in the EF Core model but not as a CLR property on the entity class. EF Core stores its value in the change tracker.

49
JuniorBeginner

What is a self-referencing relationship in EF Core?

A self-referencing relationship occurs when an entity type relates to another entity of the same type.

50
JuniorBeginner

What are best practices for relationships and loading related data in EF Core?

Model relationships according to real business rules and make principal/dependent roles, requiredness, foreign keys, and delete behavior clear. Use explicit Fluent API configuration where conventions are ambiguous.