New Posts New Posts RSS Feed: Deleted entity not removed from EntityCache
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Deleted entity not removed from EntityCache

 Post Reply Post Reply
Author
rasmus View Drop Down
Groupie
Groupie


Joined: 05-Aug-2009
Location: Denmark
Posts: 63
Post Options Post Options   Quote rasmus Quote  Post ReplyReply Direct Link To This Post Topic: Deleted entity not removed from EntityCache
    Posted: 25-Apr-2012 at 1:31pm
Hi
 
I have a scenario which looks like this:
 
Entity A contains a List of Entity B's
 
Fx. Entity A1 has relations to B1, B2 and B3
 
Now let us say two users are using the application.
 
User1 deletes Entity B2
User1 adds Entity B4
 
What user1 now sees is Entity A1 having relations to B1, B3 and B4
 
User2 makes a query the Database for all entities, and user2 now sees the new entity B4, but he also still sees the entity B2 since this entitiy is still in the entitycache.
 
Hope my example explains my problem. Basically I do not see how the entities cached can ever be deleted from the cache if they are deleted by another user - even if a reload of all the entities are made
 
How do I work around this problem?
 
Best regards,
Rasmus
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: 25-Apr-2012 at 4:10pm
Hi Rasmus,
 
From the DevForce Resource Center:
DevForce uses a MergeStrategy to determine how to reconcile potential conflicts between entities that are being merged into the cache with the entities that are already present in the cache.
 
You will find more details about it in the DevForce Resource Center's QueryStrategy and MergeStrategy topics.
 
Regards,
   Silvio.
Back to Top
rasmus View Drop Down
Groupie
Groupie


Joined: 05-Aug-2009
Location: Denmark
Posts: 63
Post Options Post Options   Quote rasmus Quote  Post ReplyReply Direct Link To This Post Posted: 25-Apr-2012 at 11:28pm
Hi Silvio
 
Thank you for your reply. But it seems to me that not QueryStrategy or MergeStrategy can solve the problem. The way I see it:
 
- if two users are using the system and both have loaded the samme entities to the cache
- user1 adds, updated or deletes entities and commits the changes
- no matter what QueryStrategy or MergeStrategy is made from user2 in subsequent queries - the user2 will see:
- The entities added by user1 (which is good)
- The updates to the entities updated by user1 (which is good)
- But entities deleted from user1 will never be removed from the cache of user2 not matter what subsequent queries are made (not matter the QueryStrategy og MergeStrategy used). Unless the enitycache of user2 is explicitly cleared and entities reloaded.
 
Is this a correct observation that deleted entities is a "special" case, and no query made will ever remove entities from a cache, only add or update?
 
Looking forward to your answer
 
Best regards,
 
Rasmus
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: 26-Apr-2012 at 10:08am
Hi Rasmus,
 
After further investigation, I could repro the issue.
The difference between my initial tests and the later is that at first I was querying for 'B' entities directly (where the QueryStrategy/MergeStrategy indeed apply), while the second time I tried to retrieved them via navigation properties.
 
Since it appears that you are trying to retrieve the B entities via NavigationProperties, here are a few approaches you can try:
 
- set the IsLoaded property of the EntityReference to false:
 
EntityTypeA.PropertyMetadata.NavigationToB.GetEntityReference(myAEntity).IsLoaded = false;
 
this will work on an per Entity/per Navigation basis.
 
- set it for all navigation properties at the EntityManager level:
 
mgr.DefaultEntityReferenceStrategy = new EntityReferenceStrategy(EntityReferenceLoadStrategy.Load, MergeStrategy.PreserveChanges);
 
You can also find this information in detail in the DevForce Resource Center.
 
Let me know if the issue still persists after trying one of the above.
 
Regards,
   Silvio.
 
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down