I'm doing a query in C# linq.
After selecting and saving the query i have to do sort it and take 15 rows...
var query = from a
[...]
select new
{
a.id,
a.desc,
}
[...]
Are there any different between doing this:
return query.OrderByDescending(o => o.id).Take(15);
and this?
return query.Take(15).OrderByDescending(o => o.id);
Thank you very much!
Yes, very much so. It's an order of operations type thing.
Say you have a data set of
A
F
B
D
F
C
and you do a return query.Take(3).OrderBy(o => o.name);
you would get
A
B
F
However, if you do return query.OrderBy(o => o.name).Take(3);
then you would get
A
B
C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With