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.
是否可以在LINQ查询语法中编写IQueryable
2 个解决方案
#1
17
There is no equivalent to Take
in the query expression syntax for LINQ in C#. The only methods that have query expression equivalents are
在C#中没有与LINQ的查询表达式语法相同的内容。具有查询表达式等价物的唯一方法是
Where,
Select,
SelectMany,
Join,
GroupJoin,
OrderBy,
OrderByDescending,
ThenBy,
ThenByDescending,
GroupBy,
Cast
This is from §7.16.2 of the specification.
这来自规范的§7.16.2。
#2
8
No. You have to use the dot syntax for that operation. Same goes for ToList
, Count
, etc...
不可以。您必须使用点语法进行该操作。 ToList,Count等也一样......
var query =
(from item in list
where predicate(item)
select func(item))
.Take(10);
#1
17
There is no equivalent to Take
in the query expression syntax for LINQ in C#. The only methods that have query expression equivalents are
在C#中没有与LINQ的查询表达式语法相同的内容。具有查询表达式等价物的唯一方法是
Where,
Select,
SelectMany,
Join,
GroupJoin,
OrderBy,
OrderByDescending,
ThenBy,
ThenByDescending,
GroupBy,
Cast
This is from §7.16.2 of the specification.
这来自规范的§7.16.2。
#2
8
No. You have to use the dot syntax for that operation. Same goes for ToList
, Count
, etc...
不可以。您必须使用点语法进行该操作。 ToList,Count等也一样......
var query =
(from item in list
where predicate(item)
select func(item))
.Take(10);