I have a situtation in which I need to get the top 15 rows from Table where the iFlag
column is marked 0.
So i have these two statements:
var t = dbContext.UnProcessedLogs.Take(15).Where(up => up.iFlag == 0).ToList();
var unProcessedlogs = dbContext.UnProcessedLogs.Where(up => up.iFlag == 0).Take(15).ToList();
What is the difference between the two statements?
Will the first one work if the top 15 rows have iFlag
marked as 1
First version : Take me 15 item, filter on them.
Second version : Take me all item, filter on them, take only 15 of the filtered items.
No, it's not the same.
Yes, they will "work", but won't do the same.
Will the first one work if the top 15 rows have iFlag marked as 1
this will just return an empty resultset.
This is not an error, it's just probably not what you want !
The first one will:
UnProcessedLogs
iFlag == 0
(which can be less than 15 obviously) The second one will:
UnProcessedLogs
down to those with iFlag == 0
If the table have 30 rows, where every other row have iFlag == 0
and the ones inbetween have iFlag == 1
, then:
iFlag == 0
) iFlag == 0
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.