This project is read-only.

Trying to get the object with highest id

May 14, 2013 at 7:58 AM
Edited May 14, 2013 at 8:01 AM
Hello, I am trying to get the object with the highest id (integer). Here is the code:
using (var odb = OdbFactory.Open(DatabaseName))
{
    var humanInfoList = from humanInfo in odb.AsQueryable<HumanCandidateWrapper>()
                                orderby humanInfo.Value.id descending
                                select humanInfo;

    int count = humanInfoList.Count<HumanCandidateWrapper>();
    if (count > 0)
            newId = humanInfoList.First<HumanCandidateWrapper>().Value.id;
}
The very odd thing is that this code gives "index out of range" exception on last line. When I debug I see that count variable is 1, so database has an object in it. So how come it is possible that First() method gives out of range exception? Shouldn't "count > 0" if clause protect this from out of range exception?
May 14, 2013 at 9:35 AM
Hello,
please rise the issue on Issue tab. If you could attach sample which is reproducing that would be great. That sounds like bug in NDatabase to Linq provider.

Thanks,
Jacek