Pomocí Net 6 a Entity Framework mám následující 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>();
}
S <Nullable>enable</Nullable>
v definici projektu dostávám varování:
Non-nullable property '...' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
V Adrese vlastnosti:
CountryCode, Locality, Location and Country.
Vidím několik možností, jak se vypořádat s tímto:
public String? CountryCode { get; set; }
public String CountryCode { get; set; } = null!;
Také bych mohl přidat konstruktor, ale ne všechny vlastnosti (například navigační vlastnosti), může být v konstruktoru.
Jaký by byl nejlepší postup?
public string? CountryCode {get;set;}
nebopublic string CountryCode { get; set;} = null!;
je irelevantní při použití EF migrace. To, co je v subjektu konfigurace je to, co je aplikován. Mýlím se?