I have the following piece of code in my LINQ:
where (tf.Shipped || tf.Ordered || tf.Processed)
Note that Shipped, Ordered and Processed are all nullable Boolean fields
I am getting the following message:
Operator || cannot be applied to operands of type 'bool?' and 'bool?'
Not sure how to resolve this as yes, they need to be nullable booleans and I need to use the OR (||).
Meskipun C dibuat untuk memprogram sistem dan jaringan komputer namun bahasa ini juga sering digunakan dalam mengembangkan software aplikasi. C juga banyak dipakai oleh berbagai jenis platform sistem operasi dan arsitektur komputer, bahkan terdapat beberepa compiler yang sangat populer telah tersedia.
C adalah huruf ketiga dalam alfabet Latin. Dalam bahasa Indonesia, huruf ini disebut ce (dibaca [tʃe]).
Bahasa pemrograman C ini dikembangkan antara tahun 1969 – 1972 oleh Dennis Ritchie. Yang kemudian dipakai untuk menulis ulang sistem operasi UNIX. Selain untuk mengembangkan UNIX, bahasa C juga dirilis sebagai bahasa pemrograman umum.
Take a step back and think about the problem. You want a collection of widgets where the widget was ordered, or the widget was shipped, or the widget was processed.
There are four possible states for your knowledge of "ordered":
There are four states but only three values possible values. Therefore if "ordered" is in the null state you do not know whether it should be included in the query results or not.
The compiler doesn't know that either.
There simply is not enough information available for the compiler to give you a query that has the semantics you want. The compiler is not going to make a guess and possibly give you bad results; the compiler is going to tell you that there's not enough information here and you need to do more work to make the query unambiguous.
What you have to do is say what to do in the case where you don't know the answer. The query "all the widgets that were ordered, shipped or processed" is impossible because some widgets we don't know whether they were ordered, shipped or processed, and so we don't know whether to include them or not. But the query "all the widgets that I know were ordered, or that I know were shipped, or that I know were processed" is a query that the compiler can make sense of:
where (tf.Shipped ?? false) || (tf.Ordered ?? false) || (tf.Processed ?? false)
That means "if I don't know whether it was shipped, etc, assume it was not".
You might instead want the query "all the widgets that definitely were, or might have been shipped, ordered or processed:
where (tf.Shipped ?? true) || (tf.Ordered ?? true) || (tf.Processed ?? true)
The compiler isn't going to guess which side you want to err on when there is insufficient information to give accurate results; the compiler might guess wrong and we're not in the business of making decisions on your behalf. You're going to have to make that decision.
Try
where (tf.Shipped == true || tf.Ordered == true || tf.Processed == true )
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