Serializing IQueryable<T> to session state server

风流意气都作罢 提交于 2020-01-04 02:04:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!