Print Page | Close Window

Saving Cache State of an Entity Group

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3049
Printed Date: 02-Apr-2025 at 6:18am


Topic: Saving Cache State of an Entity Group
Posted By: stephenmcd1
Subject: Saving Cache State of an Entity Group
Date 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



Replies:
Posted By: sbelini
Date 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.



Print Page | Close Window