© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
19 replies
ZML

ASP.NET - Domain Models Validation

Hi, I have a question about validation in domain models. In my WebApi project, I used FluentValidation for validating request data in controllers. However, when creating instances of models (before, for example, saving them to the database), I would like to perform basic validation. I’ve created methods in my classes for each field (e.g., SetName), which perform basic validation and either assign the provided value to the property or throw an exception. However, as more classes are added, some methods start to repeat or the number of methods becomes quite large if there are many properties. Is there a better way to handle this? Maybe using a pattern? Or are these methods even necessary at all? I would appreciate your help as this is quite troubling to me. I am attaching a screenshot of an example class.
q.png
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

✅ ValidationContext in ASP.NET
C#CC# / help
3y ago
[ASP.NET] B-Logic Services, Validation
C#CC# / help
4y ago
Adding comments to models in asp.net
C#CC# / help
2y ago
ASP.NET REST APIs with Custom Error Models
C#CC# / help
4y ago