Refactor Event components for improved data handling and null safety

This commit updates the Edit.razor and EventAttributes.razor components to enhance data handling and prevent potential null reference exceptions. In Edit.razor, comments are added to clarify the tracking of related careers, ensuring that the same instances are used to avoid tracking conflicts. The EventAttributes.razor component is modified to handle null EventDefinition gracefully, preventing errors when the parameter is not set. Additionally, the EventDefinitionService is updated to ensure existing careers are retrieved with tracking, improving data consistency. These changes collectively enhance the robustness and reliability of the event management features.
This commit is contained in:
2026-03-10 11:12:28 -04:00
parent 675f04afec
commit 336bbb1dec
4 changed files with 23 additions and 7 deletions
+4 -2
View File
@@ -38,9 +38,11 @@ public class EventDefinitionService
return;
}
// Get all existing careers from database (case-insensitive lookup)
// Get existing careers with tracking so we use the same instances the context
// may already be tracking (e.g. from the event's RelatedCareers). Using
// AsNoTracking() would create duplicate instances and cause "another instance
// with the same key value is already being tracked".
var existingCareers = await _context.Careers
.AsNoTracking()
.Where(c => !string.IsNullOrWhiteSpace(c.Name))
.ToListAsync();