Rohit Garg
Rohit Garg

Reputation: 598

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

Upvotes: 0

Views: 241

Answers (1)

ctacke
ctacke

Reputation: 67178

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);

Upvotes: 1

Related Questions