I have an ascx user control with and Entity Framework IQueryable property like this:
public IQueryable<Category> DataSource
{
get { return ViewState["Category"] as 开发者_如何学CIQueryable; }
set { ViewState["Category"] = value; }
}
As you can see, I tried to use ViewState to persist the value and don't have to set it on every postback but it says type is not marked as serializable...
how can I mark this as serializable?, is it recomendable to save this property on ViewState or is it better to set in on every postback?
Basically, IQueryable
is not serializable because it's not data. The query is like the means to an end, not the end itself.
I would save the result set in the Cache, not ViewState.
If you absolutely have to save the data in the ViewState you could always serialize it yourself or flatten it in some other way.
精彩评论