views:

29

answers:

1

I need to put some of the entities created via a.dbml Linq-To-Sql file into Session State. Because I am using out-of-proc State Server, they need to be serializable.

How can I achieve this?

I have tried setting the Serialization mode in the .dbml file to 'Unidirectional'.

+1  A: 

Most of the time it is impossible to serialize LINQ to SQL entities, because they reference all sorts of objects that can't be serialized or you would end up serializing an enormous object graph.

It's best to create Data Transfer Objects that you specially created for this. You can make such objects [Serializable], which allows them to be saved in an out-of-proc state (or send to a client using a web service). DTO's give you full control over what gets serialized, because they would contain primitive types or a collection of other DTO's.

Steven