How can I store a LINQ query (i.e. of type IQueryable<T>
) in SQL Server session state or any other State Server?
Asked
Active
Viewed 3,517 times
3

Kirk Broadhurst
- 27,836
- 16
- 104
- 169

Syam
- 1,629
- 1
- 20
- 32
-
a linq expression for an in-memory collection? – Nicolae Dascalu Aug 24 '11 at 22:49
3 Answers
3
You can't serialize the IQueryable
but you may be able to serialize the expression tree which generates that IQueryable
. Check out the following question and associated MSDN link.

Community
- 1
- 1

Kirk Broadhurst
- 27,836
- 16
- 104
- 169
2
You can serialize/deserialize manually the Expression that is associated to IQueriable using the visitor
Or check here: http://archive.msdn.microsoft.com/exprserialization

Nicolae Dascalu
- 3,425
- 2
- 19
- 17
-1
As far as I know, most implementations of IQueryable
are not serializable, so you can't do that. But anyway, why do you need to do that? If you want to save the results of the query, just call ToList
on the query and store the result in the session

Thomas Levesque
- 286,951
- 70
- 623
- 758
-
I am store linq queries in in-proc session until now. Now we wanted to move to a State server due to frequent session expirations on the web server. – Syam Aug 24 '11 at 22:55
-
-1 for this is a comment. There are many reasons you may want to keep the expression tree. I used this in a custom pager control implementation. – keni Apr 02 '15 at 17:39