c# - AppFabric cache and serializing IQueryable objects -
i experimenting appfabric caching , have run issue saving retrieved data in cache. root of problem seems appfabric caching requires data have datacontract , datamember attributes applied class being saved.
if case, how can save (simplified code):
var q = (from u in dbcontext.users select new { name = u.name, id = u.rowid }); cache.put(“test”, q.tolist());
calling put causes exception:
system.runtime.serialization.invaliddatacontractexception caught message=type '<>f__anonymoustypec`6[system.int32,system.string,system.nullable`1[system.int32],system.boolean,system.nullable`1[system.int32],system.int32]' cannot serialized. consider marking datacontractattribute attribute, , marking of members want serialized datamemberattribute attribute. if type collection, consider marking collectiondatacontractattribute. see microsoft .net framework documentation other supported types.
how can serialize results of iqueryable appfabric can cache it?
thank you,
rick
it isn't you're trying iqueryable, it's type anonymous. try making class results , creating 1 of store.
[serializable] public class useridpair { public string name {get;set;} public int id {get;set;} } var q = (from u in dbcontext.users select new useridpair { name = u.name, id = u.rowid }); cache.put(“test”, q.tolist());
make sure class serializable
Comments
Post a Comment