New Posts New Posts RSS Feed: Deleted child entity not represented on another client
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Deleted child entity not represented on another client

 Post Reply Post Reply
Author
John View Drop Down
Newbie
Newbie


Joined: 06-May-2013
Posts: 5
Post Options Post Options   Quote John Quote  Post ReplyReply Direct Link To This Post Topic: Deleted child entity not represented on another client
    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?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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).
Back to Top
John View Drop Down
Newbie
Newbie


Joined: 06-May-2013
Posts: 5
Post Options Post Options   Quote John Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down