Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

String property as [Required] vs non-nullable when defining a class for EF Core

$
0
0

I'm new to Blazor and EF Core and I'm learning about the mapping between C# classes and the database tables created by EF Core.

While defining a class in C#, Intellisense will complain if I define a string property as not nullable as "it must contain a non-nullable value when existing constructor". So there are 2 options here and I would like you to explain to me the implications/differences of each alternative.

  1. Mark the property as non-nullable and initialize it to an empty string.
  2. Mark the property as [Required]

Another thing that I noticed is that marking the property as [Required] doesn't remove the warning, even though the property will need to have a value when creating the object?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>