I was using .NET 5.0 (vs 2019) and would declare my model classes like this with no errors or warnings, but in .NET 6.0 (vs 2022) I get the warning with Name
and Chats
Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ASPNETCore_Backend.Models
{
public class Category
{
public int Id { get; set; }
[Required]
[MaxLength(30)]
[Column(TypeName = "varchar(30)")]
public string Name { get; set; }
// Reference to all the chats that have this category
public ICollection<Chat> Chats { get; set; }
}
}
What is the correct way to deal with this, considering this class is a Model
for Entity Framework Core.
Thank you