Print Page | Close Window

Deleted child entity not represented on another client

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4299
Printed Date: 14-Mar-2025 at 12:51pm


Topic: Deleted child entity not represented on another client
Posted By: John
Subject: Deleted child entity not represented on another client
Date Posted: 02-Sep-2013 at 9:38am
Hello.
I use DevForce 2012 in a distributed system using several Windows clients and a server.
Suppose the model has 2 entities with 1:N relation, A and B. A has a collection of 3 B's (navigation prop).
Each client loads A and all its B's using include list.
One client deletes one child B and saves changes to the server.
Then another client re-queries A.Inlude(Bs) using DataSourceOnly strategy.
Unfortunately, the other client still gets A with 3 B's rather than only 2 ones.
I also tried EntityReferenceLoadStrategy.Load and explicit Load() via EntityMetadata.
I understand it's because the deleted B remains in the cache of the other client; But I expect that the explicit load will remove it from there.
A total cache clear is not an option to me, and a manual removal for each such scenario is tedious.
Any ideas?



Replies:
Posted By: kimj
Date Posted: 02-Sep-2013 at 1:37pm
The somewhat harder to use RefetchEntities will retrieve the entity graph and remove the stale entities.  I think of it as harder to use because you must pass it the entities to refetch, but you can use FindEntityGraph if you can't easily build up the list.
 
The ListReference.Load call should also work:  A.Bs.ListReference.Load(mergeStrategy).


Posted By: John
Date Posted: 03-Sep-2013 at 5:31am
Thanks for your quick reply.
Now I see that it does work with 1:N relation (while using EntityReferenceLoadStrategy.Load), but not in N:N relation between A and B.
That means, if client1 performs a.Bs.Remove(b) and client2 loads A.Include(Bs), it still gets all the Bs, i.e. the stolen entity remain in its cache.
As a workaround, I thought to use save interceptor on the server, detect the changes and publish to the clients the entity keys that have to be re-fetched;
But in N:N relation I found no indication to the removal. A and B are at unchanged state, and the linking table is abstracted away as we know.
There must be some indication in EntityManager to entity removal in N:N relation. What is it?
Or should I take a different approach?


Posted By: kimj
Date Posted: 03-Sep-2013 at 11:55am
Unfortunately, DevForce does not handle many-to-many relations well.  Each entity does keep an internal ManyToManyChangeMap which contains information on all m-m relations, but this map is not publicly available, and even if it were, quite abstruse in how it's used.  There's probably not a reliable way to detect these changes on your server, but if you do see unchanged entities in the save interceptor prior to execution of the save, they will be part of an m-m relation.
 
For m-m relations only, doing a clear on the navigation property, eg, A.Bs.Clear(), prior to the load or re-query should work.



Print Page | Close Window