title: AppFabric cache and serializing IQueryable objects
body: <p>I am experimenting with AppFabric caching and have run into an issue with saving retrieved data in the cache. The root of the problem is that it seems that AppFabric Caching requires the data to have DataContract and Datamember attributes applied to the class that is being saved.</p>
  
  <p>If that is the case, then how can I save this (simplified code):</p>
  
  <pre><code>var q = (from u in dbContext.Users
                           select new
                           {
                               Name = u.Name,
                               Id = u.RowId
                           });
  
  cache.Put(“test”, q.ToList());
  </code></pre>
  
  <p>Calling Put causes this exception:</p>
  
  <pre><code>System.Runtime.Serialization.InvalidDataContractException was caught
   Message=Type '&lt;&gt;f__AnonymousTypec`6[System.Int32,System.String,System.Nullable`1[System.Int32],System.Boolean,System.Nullable`1[System.Int32],System.Int32]' 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.  See the Microsoft .NET Framework 
  documentation for other supported types.
  </code></pre>
  
  <p>How can I serialize the results of an IQueryable so AppFabric can cache it?</p>
  
  <p>Thank you,</p>
  
  <p>Rick</p>