简体   繁体   中英

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.

I want replacement of simple query "select top(n) from xyztable"

in my wp7 i wrote simple query "from o in hdc.messages.Take(22) where 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.

So can anyOne explain me such behavior, and replacement of top n query

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. That explains why you get 19 rows back. Instead, you want to select all where o.Msisdn == myMsisdn and then take 22 from that. Something like this:

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

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