© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
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;
  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;
  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;
  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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ FluentValidation help
C#CC# / help
4y ago
ProblemDetails and FluentValidation
C#CC# / help
3y ago
❔ FluentValidation on startup
C#CC# / help
4y ago
❔ FluentValidation Custom Client Response?
C#CC# / help
3y ago