开发者

How do I serialize Linq to SQL entities for use in out-of-proc Session State?

开发者 https://www.devze.com 2022-12-23 01:34 出处:网络
I need to put some of the entities created via a.dbml Linq-To-Sql file into Session State. Because Iam using out-of-proc State Server, they need to be serializable开发者_如何学编程.

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'.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号