문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

No. You have to use the dot syntax for that operation. Same goes for ToList, Count, etc...

var query =
    (from item in list
     where predicate(item)
     select func(item))
    .Take(10);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top