How can I store Linq to Sql objects in session using Windows Azure Cache
Service (Preview)
pI'd like to take advantage of the new Windows Azure Cache Service
(Preview) and was able to successfully store in and retrieve things from
the cache using Session by following a
href=http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-cache-service/#getting-started-cache-service
rel=nofollowthis article/a. Unfortunately we are storing Linq to Sql
objects in Session and we are not able to change that at this point. When
attempting to store such objects in Session using the Azure Cache Service,
I get the following error: /p blockquote pemType
'System.Data.Linq.EntitySet`1[cachetest.Child]' cannot be serialized.
Consider marking it with the DataContractAttribute attribute, and marking
all of its members you want serialized with the DataMemberAttribute
attribute. If the type is a collection, consider marking it with the
CollectionDataContractAttribute./em /p /blockquote pI used the
Unidirectional Serialization Mode for my data context, so all declarations
are already decorated with DataContract and DataMember attributes (see
code sample below). /p pI've looked into using a Custom Serializer a
href=http://msdn.microsoft.com/en-us/library/windowsazure/hh552969.aspx
rel=nofollowsimilar to this article/a and a
href=http://stackoverflow.com/questions/12707939/how-to-write-a-custom-serializer-by-using-datacontractserializer-for-generic-typthis
article on stackoverflow/a, but received an error that matched the exact
error described towards the end a
href=http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx
rel=nofollowof this article/a, in which it is stated that /p blockquote
pthe ASP.NET providers for Cache do not support binary or custom
serialization types/p /blockquote pSince a custom serializer is not an
option, how else can I store Linq to Sql objects (with parent-child
relationships) in Session using Windows Azure Caching?/p pI've broken out
the code that illustrates the issue below.br The Linq DataContext: /p
precodenamespace cachetest { using System.Data.Linq; using
System.Data.Linq.Mapping; using System.Data; using
System.Collections.Generic; using System.Reflection; using System.Linq;
using System.Linq.Expressions; using System.Runtime.Serialization; using
System.ComponentModel; using System; public partial class
TestModelDataContext : System.Data.Linq.DataContext { private static
System.Data.Linq.Mapping.MappingSource mappingSource = new
AttributeMappingSource(); #region Extensibility Method Definitions partial
void OnCreated(); partial void InsertParent(Parent instance); partial void
UpdateParent(Parent instance); partial void DeleteParent(Parent instance);
partial void InsertChild(Child instance); partial void UpdateChild(Child
instance); partial void DeleteChild(Child instance);
No comments:
Post a Comment