views:

26

answers:

2

How can I make my Linq to SQL query logic execute on the server?

I have a created a Linq query and returned it as an IEnumerable. Subsequent operations on the query such as .Count() or .Take(5) are evaluated on the client in CLR, rather than on the server.

+2  A: 

Converting to IEnumerable will cause the query to be executed - as a result the data is now on the client side.

If you want to execute paging on the server side, you should perform those operations while it is still a late executing IQueryable.

David
A: 

IEnumerable was the problem. Returning the Linq.DataQuery as an IQueryable allows Linq to SQL to add additional operations to the query. Figured this out as I was describing the problem.

Michael McHenry
You should add this as a comment to the question and not as as an answer. Beside, it would be nice if you accepted David answer
AlbertEin
Sorry. I'm new here. In fact, I joined just to solve this problem. I would accept David's answer if I could see how.
Michael McHenry
OK, figured that out with the checkbox. The answering my own question was a little silly, but I was stuck on this for an hour until I actually wrote down the word "IEnumerable" in the post and went and chased after that.
Michael McHenry