Custom ISerializable from Base class

71 Views Asked by At

I'm trying to keep my session in SQLServer. I know if an object needs to be stored in SQL than it needs to be Serialized. And i also know that i need to put [Serializable] attribute on every class if necessary. But the problem is i have more than 2000 object and keeps growing. They are bound together very tightly. If i put one of them to session probably i need to add [Serializable] attributre to all of them, which is pointless. What i want to know is how to write the same code for ISerializable interface just like [Serializable] attribute does in the base class? Any idea? Or should i add [Serializable] to every class. If i do is there any downside?

1

There are 1 best solutions below

4
Martino Bordin On BEST ANSWER

Create a more specific, little class that represent the data you actually need to persist in session and apply the [Serializable] attribute only on that class.

Please note that [Serializable] is NOT required by Sql Server itself but by the session management in asp.net session