I'm working on an app using a WCF server (using the new beta Mindscape LightSpeed ORM) and consuming the service at an ASP.NET MVC2 client. My entities show up at the client as array of T
, or IEnumerable<T>
. I want to do cool things with the data after it has arrived, but the LINQ syntax required IQueryable<T>
.
I know there is a way to convert from IEnumerable<T>
to IQueryable<T>
, but I have had no luc开发者_开发百科k so far searching for it. Can anybody help?
Thanks, Dave
Well, I suspect you're thinking of Queryable.AsQueryable()
- but what makes you think that you need to use IQueryable<T>
to use LINQ? Converting an IEnumerable<T>
to IQueryable<T>
won't give you most of the benefits of IQueryable<T>
.
LINQ to Objects is all based around IEnumerable<T>
. If you're happy working with the data you've already received, that's all you need.
If, however, you want to express a query at your client and tell the WCF server to execute that query (e.g. performing the filtering in the database or at least at the WCF side), that's when you'd use IQueryable<T>
. You might find my Edulinq post about IQueryable<T>
useful. You'd need some way of representing the service as an IQueryable<T>
though - and at that point you're beyond my WCF knowledge.
Try the following method:
AsQueryable()
精彩评论