Let’s go by part. When you said "model that comes from the request" I assume it is a Dto, a Viewmodel or any name for an object that only carries attributes. It is not interesting to use these objects as your Model or Domain entities to avoid coupling the Model layer with the Controller layer. To validate this input data, you can use Data Annotation just like Nilton said.
Now thinking that we are already talking about the domain level. It is not the obligation of the Entity Framework to validate this subject. The obligation is of your entity. Following the object orientation paradigm, who must validate the Client class is the Client itself.
I recommend you use a pattern little recognized by name, but used quite a lot, which is the Good Citizen Pattern. In this pattern, your object must validate whether your own state is consistent, becoming a good citizen.
There are several ways to do this, for example:
The manufacturer of a class serves much more than injecting
dependency, it should be used to leave the class in a
valid state whenever possible. There will be cases where only the manufacturer is not sufficient.
It is common (even if it is not specified directly in good Citizen Pattern) to make a validation contract, for example Ivalidated. In this case, have all classes implement a validation method, so before Entity starts playing its role, you can validate the entity and, if possible, even retrieve it if needed.
Example:
var meuNovoCliente = new Cliente(nome: "Gabriel Coletta", idade: 23);
var clienteValido = meuNovoCliente.Validar();
if(clienteValido) {
//chamar a camada que faz o INSERT, por exemplo;
}
Would validating what you say be something like, for example, a field that does not accept negative values? If it is the obligation to do so, it becomes your domain.
– Gabriel Coletta
@Gabrielcoletta would like to, for example, receive a model of the client type and validate if this model has all the mandatory data of the database table, besides validating if the username has no space, if the password meets the criteria, etc.
– Csorgo
@Csorgo takes a look at my answer, it will be nicer yet your example, and you do not need to be doing if throughout post.
– Thiago Loureiro