Entity Framework Core Interview Question #37
What is relationship fix-up in EF Core?
Relationships, Navigation Properties & Loading Data Junior Beginner
Quick Interview Answer
Relationship fix-up is EF Core's process of keeping navigation properties and foreign-key values synchronized for tracked entities.
Detailed Explanation
Relationship fix-up is EF Core's process of keeping navigation properties and foreign-key values synchronized for tracked entities.
When EF Core discovers that two tracked entities are related, it can populate reference and collection navigations accordingly. Similarly, changing a navigation can cause the corresponding foreign key to be updated.
This behavior is part of change tracking and helps keep an in-memory entity graph consistent.
Code Example
var order = await db.Orders.FindAsync(orderId);
var customer = await db.Customers.FindAsync(customerId);
order!.Customer = customer!;
// EF Core keeps CustomerId consistent for the tracked relationship.
await db.SaveChangesAsync();