简体   繁体   中英

How to compare decimal with EF4 and Mysql

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM