tags:

views:

38

answers:

1

Is there any reason why the class 'SubSonic.Repository.SubSonicRepository' in the SubSonic.Core assembly (3.0.0.3) is not marked as Serializable? Or know of a workaround to serialize a subsonic generated class.

I added a subsonic generated object into the viewstate and got an error saying the object wasn't marked as Serializable. So I created an extention (using a partial class) to my generated object which I thought would be enough but it's now complaining about the above class in the SubSonic Assembly needs marking as Serializable too.

+1  A: 

When a class is not serializable (and other classes from the same namespace are) there usually is a good reason.

The repository probably contains (or manages) a connection to the Db, and a connection is not serializable, for good reasons. Because on deserialization, it would be complex (and possibly unsecure) to establish another connection. You couldn't get the same connection back anyway.

Henk Holterman
Thanks Henk, I didn't think that the base class might contain such details. You're right though it's possible and certainly could be a problem adding such sensitive info into the viewstate.I guess this is were SubSonic not supporting POCO becomes an issue?
DaveHogan
SubSonic supports POCOs - just use the SimpleRepository. Btw. I'd recommend to use some special view model classes that you use to store your entities in viewstate because 1:n, 1:1 relations are loaded lazy.
Saintedlama