linq到sql ExecuteQuery()作为IQueryable [英] linq to sql ExecuteQuery() as IQueryable
问题描述
ExecuteQuery()方法返回IEnumerable,但是有没有办法使它返回IQueryable?
ExecuteQuery() method returns an IEnumerable but is there a way to make it return IQueryable?
推荐答案
好吧,您可以调用AsQueryable
,但是它没有任何用处.问题在于,当您使用ExecuteQuery
时,查询不是 composable ,因为LINQ to SQL不能理解"它.
Well, you can call AsQueryable
, but it won't do any good. The problem is that when you use ExecuteQuery
, the query isn't composable because LINQ to SQL doesn't "understand" it as such.
IQueryable<T>
的核心目的之一是允许将查询的各个方面组合在一起,然后LINQ to SQL可以将它们转换为单个SQL查询.当查询的某一位实际上是不透明的时,这是行不通的.
One of the core purposes of IQueryable<T>
is to allow the various aspects of a query to be composed together and then LINQ to SQL can convert them into a single SQL query. That just doesn't work when one of the bits of the query is effectively opaque.
这篇关于linq到sql ExecuteQuery()作为IQueryable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!