Error comparing database data with empty form field

Asked

Viewed 32 times

-2

I need to check if there is already a registered document number not to repeat it. However, the field Document allows null, so there is an error when comparing a database value with a null value of my form. What to do so that the check returns no error if such form field contains null value?

Here I return all records from the database

var pontoAtendimentoRecuperados = RecuperarTodos(identidadeAtual);

Here I compare if any of the data brought from the database is equal to the content of the form field

var verificaDocumentoExistente = pontoAtendimentoRecuperados.Where(p => pontoAtendimento.Documento.Equals(p.Documento) && pontoAtendimento.Id != p.Id);

Error occurs in second line of code.

inserir a descrição da imagem aqui

  • What error is occurring?

  • @Cypherpotato includes the image that represented the error.

1 answer

0

Before making the comparison it is necessary to verify if the value is not null.

var verificaDocumentoExistente = pontoAtendimentoRecuperados.Where(p => p.Documento != null && pontoAtendimento.Documento.Equals(p.Documento) && pontoAtendimento.Id != p.Id);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.