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.
To check if a value is of boolean type, check if the value is equal to false or equal to true , e.g. if (variable === true || variable === false) . Boolean values can only be true and false , so if either condition is met, the value has a type of boolean.
The way you typically represent a “missing” or “invalid” value in C# is to use the “null” value of the type. Every reference type has a “null” value; that is, the reference that does not actually refer to anything.
In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A string will be null if it has not been assigned a value. A string will be empty if it is assigned “” or String.
You typically use a nullable value type when you need to represent the undefined value of an underlying value type. For example, a Boolean, or bool , variable can only be either true or false . However, in some applications a variable value can be undefined or missing.
Try this:
.Where(it => !(it.isDeleted ?? 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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With