简体   繁体   中英

Why putting OR with three boolean type columns would randomly fetch or sometimes not fetch the data?

I have a table

Students

now students has 3 Booleans checks

1. IsRecordArchived
2. IsActive
3. IsOnProbation

The Booleans are not relevant to each other and doesn't depend on each other but the record should not appear or included in the result set if any of it is TRUE .

eg

A student can be I sRecordArchived = TRUE but might not be the other two ie IsActive= false and IsOnProbation = false or could be IsActive= True and IsOnProbation= false or true even.

Or it could all be equal to TRUE . Could be anything but ultimately it should not be included in the record.

Now, my query

var students= db.Students.where(s=> !IsActive || !IsRecordArchived || !IsOnProbation).ToList();

Would sometimes work but sometimes not. How do I adjust these?

eg

studnet records

ID  Name  IsArchived  IsDeleted IsOnProbation
1   Tom       1          0           0
2   Dick      1          1           0
3   Harry     0          0           1
4.  Amas      0          0           0

Now, according to my query; only 4. Amas should be in the result set not the others.

the record should not appear or included in the result set if any of it is TRUE.

Does this really implement that logic?

var students= db.Students.where(s=> !IsActive || !IsRecordArchived || IsOnProbation).ToList();

That's going to get records where either of IsActive and IsRecordArchived is false or IsOnProbation is true .

If you want records where none are true , ie all are false , then you need to specify that all are false and use AND operators:

var students= db.Students.Where(s=> !IsActive && !IsRecordArchived && !IsOnProbation).ToList();

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