Using Net 6 and Entity Framework I have the following entity:
public class Address {
public Int32 Id { get; set; }
public String CountryCode { get; set; }
public String Locality { get; set; }
public Point Location { get; set; }
public virtual Country Country { get; set; }
public virtual ICollection<User> Users { get; set; } = new List<User>();
}
With <Nullable>enable</Nullable> in project definition I am getting the warnings:
Non-nullable property '...' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
In Address properties:
CountryCode, Locality, Location and Country.
I see a few options to deal with this:
public String? CountryCode { get; set; }
public String CountryCode { get; set; } = null!;
I could also add a constructor but not all properties (for example, navigation properties) can be in the constructor.
What would be the best approach?
