3
I have a similar problem in two ASP.NET applications with Entity Framework.
When I try to update an entity that already has all the required attributes filled I get an exception from EntityValidationErrors
, however that property is described in validarion
this filled.
The strange thing is that if I put the breakpoint and check the attributes of the object they are all filled and it does not cause the error.
In one of the applications I am circumventing this problem by making the property receive itself or simply accessing the property and throwing its value in any variable:
ComentariosBlog model = _comentariosBlogNegocios.GetById(idComentatio.Value);
if (model == null)
return HttpNotFound();
model.Ativo = status.Value;
var teste = model.Publicacao; //<----Contorno
idPost = model.PublicacaoId;
_comentariosBlogNegocios.Salvar(model);
I already have a block of Try Catch that handles this error, the problem is that the object is with all the mandatory properties filled and I have to do a "Gambi" so that it does not generate errors like this in the code above! The simple fact of accessing the property and throwing it in any variable already stops giving error, but I need a more correct solution to this problem, as I said this is only a "Gambi"!
Below is the details of the error that is generated:
In this image we can see that the mentioned property is already filled:
Here is the error message inside the Try catch:
possible duplicate of How to fix Entityvalidationerrors
– Leonel Sanches da Silva
There is already an error handling to know which property the RU says is not filled in. The problem is that this property is already filled and is not a simple problem of handling Entityvalidationerrors.
– Eduardo Barbosa Oliveira da Si
I need you to explain in your question how this error handling is done. There are several types of validation that are done by
DefaultModelBinder
, not only the field completed or not.– Leonel Sanches da Silva
Good afternoon @Ciganomorrisonmendez, sorry for my ignorance on the subject but I had already done the validation as recommended in the publication [link]http://answall.com/questions/17644/como-correctr-o-entityvalidationerrors[link]. However when I place the breakpoint and check the properties of the object I am trying to save, the property that is pointed out by Dbentityvalidationexception is a property that has value, but if before Savechanges() i put a test variable receiving the property value the code does not generate exception.
– Eduardo Barbosa Oliveira da Si
What error appears in
ve.ErrorMessage
, in the solution already mentioned?– Leonel Sanches da Silva
@Ciganomorrisonmendez I made an issue in the question with the prints of the errors, I do not know if it helps?
– Eduardo Barbosa Oliveira da Si
Please put your
Model
on the question. Something caught my attention on your screen.– Leonel Sanches da Silva
@Ciganomorrisonmendez you tell my entity as print I entered now?
– Eduardo Barbosa Oliveira da Si