New Posts New Posts RSS Feed: Saving Cache State of an Entity Group
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Saving Cache State of an Entity Group

 Post Reply Post Reply
Author
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Topic: Saving Cache State of an Entity Group
    Posted: 21-Oct-2011 at 5:03pm
I just upgraded to 6.1.3.1 and ran into a small problem.  Our app caches a lot of data to Isolated Storage and we've broken up the cache saves so we write to a separate file for each Entity Group.  Previously, we could do code like this without a problem:
//Find a random entity group that has at least one entity in it (in our real 
//   app, this logic is different but this is an easy way to reproduce the problem).
var aNonEmptyGroup = _entityManager.GetEntityGroups().First(g => g.Count() > 0);

using (var dummyStream = new MemoryStream())
{
    //Save the entities in the given group out to the stream
    _entityManager.CacheStateManager.SaveCacheState(aNonEmptyGroup, dummyStream);
}
However under 6.1.3.1, this code throws an ArgumentException with a message of "already an EntityAspect".  It seems some logic is trying to wrap an Entity Aspect in another Entity Aspect and it gets confused.  I found an easy workaround but I'm not entirely sure it's the best way.  The new code does this:
//Go through the EntityAspects in the group and grab the corresponding Entity
//Is this the correct way to do it?  Will the .Entity property always have a value?
var entities = aNonEmptyGroup.Select(entityAspect => entityAspect.Entity);

//Save the entities in the given group out to the stream
_entityManager.CacheStateManager.SaveCacheState(entities, dummyStream);
My question is whether the code above is the best approach.  Also, I guess this is a breaking change that could be documented?  Unless it's actually a bug and I should be able to use my original code in 6.1.3.1?

Thanks!
-Stephen
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 01-Nov-2011 at 12:07pm
Hi Stephen,
 
This is indeed an undocumented breaking change. I'll update the release notes.
 
EntityGroup now implements an IEnumerable<EntityAspect> instead of an IEnumerable<Object> (where the Object is an entity).
 
You're workaround is the correct approach.
 
Regards,
   Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down