[英]Is there a difference between these two Search Statements Entity Framework
I have a situtation in which I need to get the top 15 rows from Table where the iFlag
column is marked 0. 我有一个位置,我需要从表中获取前15行,其中
iFlag
列标记为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 如果前15行的
iFlag
标记为1,那么第一行是否iFlag
First version : Take me 15 item, filter on them. 第一个版本:带我15项,过滤它们。
Second version : Take me all item, filter on them, take only 15 of the filtered items. 第二个版本:带我所有项目,过滤它们,只采取15个过滤项目。
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
如果前15行的iFlag标记为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
UnProcessedLogs
iFlag == 0
(which can be less than 15 obviously) iFlag == 0
(显然可能小于15) The second one will: 第二个将:
UnProcessedLogs
down to those with iFlag == 0
UnProcessedLogs
所有行过滤到iFlag == 0
If the table have 30 rows, where every other row have iFlag == 0
and the ones inbetween have iFlag == 1
, then: 如果表有30行,其中每行都有
iFlag == 0
且其中的行有iFlag == 1
,那么:
iFlag == 0
) iFlag == 0
) iFlag == 0
iFlag == 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.