问题
How can I store a LINQ query (i.e. of type IQueryable<T>
) in SQL Server session state or any other State Server?
回答1:
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.
Can you Pass Func<T,bool> Through a WCF Service?
http://archive.msdn.microsoft.com/exprserialization
回答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
回答3:
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
来源:https://stackoverflow.com/questions/7183199/serializing-iqueryablet-to-session-state-server