Remoting and UnitOfWork2 serializing entire object graph

Posts   
 
    
rbrown
User
Posts: 36
Joined: 11-Jun-2008
# Posted on: 09-Jul-2008 22:41:00   

Hi, I have a project where the client loads an entity collection from a server using remoting (Manager templates), then makes updates and passes a UnitOfWork2 back to the server to persist changes. I noticed that when I load up a large number of entities, edit a single entity and pass the unit of work back to the server, it takes about the same amount of time to send across the wire. I started investigating and found that the entire entity graph is being serialized and sent back across the wire, even though only one entity has changed.

To explain my object model briefly, a Tag has many Readings. I load up the Reading entities with a prefetch to load the parent Tag entities. Now when I edit a single Reading value and try to send it back across to the server, its parent Tag comes with it, along with the Tag's collection of Readings (thus the entire object graph comes back to the server).

Is there a way to send back only the single Reading entity without the related entities?

I am using LLBLGen 2.6 Final, with Adapter + Manager templates (slightly tweaked), .NET 3.5 (C#), using this over .NET remoting.

Thanks! Randy

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 10-Jul-2008 10:27:36   

Does the UnitOfWork (the one you send back), contains the modified entity or the entire graph?

rbrown
User
Posts: 36
Joined: 11-Jun-2008
# Posted on: 10-Jul-2008 15:46:30   

Even if I only add the modified entity to the UOW, basically the whole graph comes along with it because of the relations.

Parent has many children. I send one child entity back, but since it has a reference to its parent, the parent is also serialized and thus the parent's entire list of children comes back to the server.

The UOW operation completes successfully and only the updated entity gets persisted, so functionally it is correct... but I'm looking for a way to avoid sending the other related entities back across the remoting wire, as that takes several seconds when the parent has many children.

Is there a way to have the UOW only serialize the single entity that needs to be updated, without grabbing all its related entities during the serialization process?

For example, should I remove the child entity from it's parent collection before adding it to the UOW? (I guess I would need to disable the deleted entity tracking, then I would have to re-add it after committing the uow...)

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 10-Jul-2008 15:48:41   

There's a setting on the unitofwork: OptimizedSerialization You should set that to true (then only the changed entities and entities required for persistence are serialized), however that setting is already true by default, so it can be the changed entity refers to a lot of other entities and these are serialized then as well... (as serialization is recursive).

If you want to optimize this, you should do something like: ReadingEntity toSend = new ReadingEntity(); toSend.Fields = changedReadingEntity.Fields; toSend.IsNew = false;

// send toSend over the wire.

There's currently no cut-off feature / diffgram feature build into the unitofwork or other object.

rbrown
User
Posts: 36
Joined: 11-Jun-2008
# Posted on: 10-Jul-2008 15:52:59   

If you want to optimize this, you should do something like: ReadingEntity toSend = new ReadingEntity(); toSend.Fields = changedReadingEntity.Fields; toSend.IsNew = false;

// send toSend over the wire.

Thanks! I believe this will solve the problem. I will try implementing this.

rbrown
User
Posts: 36
Joined: 11-Jun-2008
# Posted on: 21-Jul-2008 17:00:19   

I implemented the approach we discussed (creating a new entity, setting the Fields, etc) and that appears to be working the way we need it. Thanks!