Microsoft introduced the nameof operator in C# 6 which allows us to reference the property on the Category class directly. If we change the name of the property, the change will propagate throughout the system instead of us having to go update every magic string of the property, which is very manual and error prone.
Proposal:
ViewBag.CategoryId = new SelectList(_db.Categories, nameof(Category.CategoryId), nameof(Category.Name));
Thank you for suggesting this @doctorcrawford and tagging me. I don't actively contribute to Epicodus repositories anymore, so I'm tagging @mtb116 who should be able to weigh in on this.
https://github.com/epicodus-lessons/section-4-to-do-list-with-many-to-many-csharp-net6/blob/13f21bd63f3a154cc2f77cc76c88d410aa9f3190/ToDoList/Controllers/ItemsController.cs#LL29C81-L29C81
Microsoft introduced the nameof operator in C# 6 which allows us to reference the property on the
Category
class directly. If we change the name of the property, the change will propagate throughout the system instead of us having to go update every magic string of the property, which is very manual and error prone.Proposal:
ViewBag.CategoryId = new SelectList(_db.Categories, nameof(Category.CategoryId), nameof(Category.Name));