Linq causes collection to disappear when trying to use OrderByDescending
Posted
by Jeremy B.
on Stack Overflow
See other posts from Stack Overflow
or by Jeremy B.
Published on 2010-04-16T19:11:41Z
Indexed on
2010/04/16
19:13 UTC
Read the original article
Hit count: 297
For background, I am using MongoDB and Rob Conery's linq driver. The code I am attempting is thus:
using (var session = new Session<ContentItem>())
{
var contentCollection = session.QueryCollection.Where(x => x.CreatedOn < DateTime.Now).OrderByDescending(y => y.CreatedOn).ToList();
ViewData.Model = contentCollection;
}
this will work on one machine, but on another machine I get back no results. To get results i have to do
using (var session = new Session<ContentItem>())
{
var contentCollection = session.QueryCollection.Where(x => x.CreatedOn < DateTime.Now).ToList();
ViewData.Model = contentCollection.OrderByDescending(y => y.CreatedOn).ToList();
}
I have to do ToList() on both lines, or no results. If I try to chain anything it breaks. This is the same project, all dll's are locally loaded. Both machines have the same framework, versions of Visual studio and addons. the only difference is one has VisualSVN the other AnkhSVN. I can't see those causing the problem.
Also, while debugging, on the machine that does not work you can see the items in the collection, and if you remove ordering all together it will work. This has got me completely stumped.
© Stack Overflow or respective owner