简体   繁体   English

在sql ce wp7中选择前n个

[英]select top n in sql ce wp7

I searched a lot..but i was unable to find a good link on sql compact edition for windows phone 7. 我进行了很多搜索..但我无法在Windows Phone 7的SQL Compact Edition上找到良好的链接。

I want replacement of simple query "select top(n) from xyztable" 我想替换简单的查询“从xyztable选择top(n)”

in my wp7 i wrote simple query "from o in hdc.messages.Take(22) where o.Msisdn == myMsisdn orderby o.MessageId select o);" 在我的wp7中,我写了一个简单的查询“从hdc.messages.Take(22)中的o,其中o.Msisdn == myMsisdn orderby o.MessageId select o);”

but i didnt get desired outputs..It works on some contigous memory. 但是我没有得到想要的输出。它可以在一些连续的内存上工作。 It gave me 19 rows but actually there are 25 rows. 它给了我19行,但实际上有25行。

So can anyOne explain me such behavior, and replacement of top n query 所以任何人都可以向我解释这种行为,并替换前n个查询

You have an "order of operations" problem here. 您在这里有一个“操作顺序”问题。 This code: 这段代码:

from o in hdc.messages.Take(22) where o.Msisdn == myMsisdn select o

First gets 22 messages, and then selects from that subset those that match your o.Msisdn == myMsisdn check. 首先获取22条消息,然后从该子集中选择与o.Msisdn == myMsisdn检查相匹配的o.Msisdn == myMsisdn That explains why you get 19 rows back. 这就解释了为什么要返回19行。 Instead, you want to select all where o.Msisdn == myMsisdn and then take 22 from that. 相反,您想要选择所有o.Msisdn == myMsisdn ,然后从中取22。 Something like this: 像这样:

(from o in hdc.messages where o.Msisdn == myMsisdn select o).Take(22);

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

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