简体   繁体   中英

Cannot apply operator '==' to type 'System,.Nullabe<decimal>' and 'System.Nullable<double>' Error

I am trying to understand why the following method below is throwing this error. I would appreciate it if some one would help or point me in the right direction.

 public List<Data> GetResults(string manufacturer, int? vehicle, double? engine )
        {
var results =c ontext.Data.Where(x => x.Name == manufacturer)
                        .Where(x => x.ModelId == model)
                        .Where(x => x.EngineLitreCapacity == engine) // <<  error occurs on this line!
                        .GroupBy(x => x.EngineLitreCapacity)
                        .Select(x => x.FirstOrDefault())
                        .ToList();

        }

What am i doing doing wrong and how would i go about in resolving my query above? Thank you

EngineLitreCapacity seems to be a decimal? while your engine is a double? . Those variables are not comparable without casting.

The easy solution is to make engine a decimal? . That might cause casting issues later on, which you have to resolve. It is definitely a bad idea to just cast the double? since its precision might cause the equation to fail anyways.

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