C#C
C#3y ago
barcode

❔ FluentValidation DTO

Hello, lets say I have a dto like this:

  public uint CenterId { get; set; }

    public int Page { get; set; } = 0;
    public int Count { get; set; } = 10;


When the user supplies a request, if he doesn't supply center id it will be auto initialized to 0, making it impossible to detect if he even supplied that property

The solution is making the property nullable and checking if .NotNull()
  public uint? CenterId { get; set; }

    public int Page { get; set; } = 0;
    public int Count { get; set; } = 10;


however then IDE cries for nullables so we come to this:
  public uint CenterId { get; set; } = null!;

    public int Page { get; set; } = 0;
    public int Count { get; set; } = 10;


Is this the correct way to setup DTOs?
Was this page helpful?