Question

I need select with decimal field...

this work!!

var id = context.Localizacoes.Where(x => x.Horario == data && x.IdFuncionario == id_funcionario).FirstOrDefault().IdLocalizacao;

but I add decimal var for compare.. "latitude"

 id = context.Localizacoes.Where(x => x.Horario == data && x.IdFuncionario == id_funcionario && x.Latitude == latitude).FirstOrDefault().IdLocalizacao;

return this error:

System.NullReferenceException: Object reference not set to an instance of an object.

Was it helpful?

Solution

Probably FirstOrDefault returns null

Try to check returning value then access your property:

var result = context.Localizacoes
            .Where(x => x.Horario == data && x.IdFuncionario == id_funcionario && x.Latitude == latitude)
            .FirstOrDefault();

if(result != null)
   id = result.IdLocalizacao;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top