Best practice in Adapter when serializing dirty entities

Posts   
 
    
saggett
User
Posts: 50
Joined: 12-Nov-2007
# Posted on: 07-May-2008 15:29:02   

This is a question about best practice for performance with Adapter when serializing dirty object graphs that's best illustrated by the usual Customer ... Order ... OrderDetail stuff.

Say I'm creating a new Order, with a few Order Details, like so:

var cust = FetchCustomer();
var order = new OrderEntity();
order.Customer = cust;
order.DateCreated = DateTime.Now;
order.OrderDetails.Add(CreateOrderDetail(...));
order.OrderDetails.Add(CreateOrderDetail(...));
order.OrderDetails.Add(CreateOrderDetail(...));

You get the idea.

I then want to save my new order via my WebService.SaveOrder(OrderEntity order) method. But when this is serialized into xml it's not just the Order and Order Details entities which are serialized, but the entire Customer entity as well. Now it seems to me that the only necessary bit of data to save the new order is the OrderEntity.CustomerId property, all the Customer data is unchanged and so it's pointless to serialize this also. Because even if we need the Customer entity in the SaveOrder(order) implementation Service-side, in most setups (where the client must communicate over the internet with the app server, but the db server is on the same LAN as the app server) it's more efficient to simply fetch it from the db than to require the client to serialize it back to the web service.

So my question is, is there a way to strip off unnecessary, clean data when serializing dirty entities back to the service? I'm aware that when creating order one could simply do order.CustomerId = customer.Id instead of order.Customer = customer, but that imposes restrictions on UI Developers that don't always get obeyed and it restricts possibilities data binding wise.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 07-May-2008 18:06:50   

Personaly I don't think there is a better way other than setting the FK directly.

saggett
User
Posts: 50
Joined: 12-Nov-2007
# Posted on: 08-May-2008 12:06:48   

Should I post this as a feature request? Or is there some code I could write to strip off any given child entity without affecting the foreign key id on the parent entity? Obviously order.Customer = null won't work because order.CustomerId will then equal 0. order._Customer would work I think but that's a private field.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 08-May-2008 12:53:04   

It's not possible to strip it off that easily. As there's an easy workaround: setting the FK in order, it's not likely we'll add this soon.

Frans Bouma | Lead developer LLBLGen Pro