简体   繁体   English

这两个搜索语句实体框架之间是否存在差异

[英]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: 第一个将:

  1. Take the first 15 rows of UnProcessedLogs 取前15行UnProcessedLogs
  2. Then filter those down to those with iFlag == 0 (which can be less than 15 obviously) 然后将那些过滤到那些iFlag == 0 (显然可能小于15)

The second one will: 第二个将:

  1. Filter all the rows of UnProcessedLogs down to those with iFlag == 0 UnProcessedLogs所有行过滤到iFlag == 0
  2. Take the first 15 of those 拿前15个

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 ,那么:

  1. The first query will return 7-8 rows (of the first 15 in the table, pick the ones with iFlag == 0 ) 第一个查询将返回7-8行(表中的前15行,选择iFlag == 0
  2. The second query will return all 15 with iFlag == 0 第二个查询将返回全部15个iFlag == 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM