required modifier
The C# required keyword on a property, which makes the compiler refuse any construction that does not set it.
In more detail
public required string Name { get; set; } means no Product can exist without a name. It guards construction in C# only; database nullability still comes from the EF Core model.
Related terms
- property — A named value belonging to an object; in languages such as C# and Python, it can also be a member that looks like a field but runs code when read or written.
- object initializer — C# syntax that sets properties in braces right after new, such as new Product { Name = "Kettle", Price = 24.50m }.
- init accessor — A property accessor written init instead of set, which allows the value to be assigned only while the object is being created.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- Entity Framework Core: Code First and Migrations — Modern .NET Core, C# & Enterprise Microservices