Is the following the best way of getting a single result:

Site thisSite = (from site in Query<site>.All where site.OldSiteId == 13 select site).First<site>();

You do not appear to support "Single" ?

Tony Steele NeighbourNet Ltd

This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by Anonymous.

asked Jul 28 '09 at 00:15

Editor's gravatar image


No, we do. Single must work, there are even special tests for this. I remember we did a lot to support this construct in subqueries (really non-trivial, e.g. EF does not support this).

To be checked.

(Jul 28 '09 at 00:15) Alex Yakunin Alex%20Yakunin's gravatar image

One Answer:

Try the following queries (they are same): Site thisSite = (from site in Query<site>.All where site.OldSiteId == 13 select site).Single(); Site thisSite = Query<site>.All.Where(site => site.OldSiteId == 13).Single(); Site thisSite = Query<site>.All.Single(site => site.OldSiteId == 13);

The following exceptions may occur during execution of 'Single' method:

  • System.InvalidOperationException: Sequence contains more than one element. - when more than one element returned by query

  • System.InvalidOperationException: Sequence contains no elements. - no element returned at all.

answered Jul 28 '09 at 05:52

Editor's gravatar image


Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA