简体   繁体   中英

How to check if nullable boolean is not true?

Righ now I have this that works, but its ugly and long:

        var details = dc.SunriseShipment
            .Where(it => (it.isDeleted == null || it.isDeleted == false));

Is there a better way to do this? I tried "it.isDeleted != true" and "it.isDeleted ?? false == false" but they are not working.

试试这个:

.Where(it => !(it.isDeleted ?? false));
.Where(it => it.isDeleted == (bool?)false);

There is an GetValueOrDefault method which returns a default value when the value is null:

var details = dc.SunriseShipment
.Where(it => !it.isDeleted.GetValueOrDefault(false));

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