How can I write Take(1) in query syntax

Steven Wexler picture Steven Wexler · Jul 26, 2013 · Viewed 8.7k times · Source

Is it possible to write IQueryable<MyObject> = query.Take(1) or something equivalent in LINQ query syntax. I'm using C# 5 and EF 5.

Answer

jason picture jason · Jul 26, 2013

There is no equivalent to Take in the query expression syntax for LINQ in C#. The only methods that have query expression equivalents are

Where,
Select,
SelectMany,
Join,
GroupJoin,
OrderBy,
OrderByDescending,
ThenBy,
ThenByDescending,
GroupBy,
Cast

This is from §7.16.2 of the specification.