Serialize only changed entities back to WebAPI ?

Posts   
 
    
HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 12-Aug-2015 14:17:03   

Hello, I'm starting a new project and want to take an approach of WebAPI REST architecture (in combination with a WPF smartclient) To maximally leverage LLBLGen, i would use the adapter model, and reuse the DatabaseGeneric classes in backend as well as in the WPF client, using the JSON serialization to communicate with the WebAPI backend as Frans explained in his blog a while ago (http://weblogs.asp.net/fbouma/how-to-make-asp-net-webapi-serialize-your-llblgen-pro-entities-to-json)

I'm still a bit struggling with the following scenario: Imagine the classic User-Orders-Orderlines-Products entity model and a UI where the end-user can edit a grid with orderlines after choosing a user and order.

The webAPI api would be something like : GET api/users <- get all users GET api/users/123 <- get user with id 123 (with prefetched orders !) GET api/orders/123 <- get the order with id 123 (with prefeteched orderlines and products !)

So far so good, it would get deserialized in the client and data-bound to listboxes or grids or whatnot.

But what about sending modified data back ? When the end-user for example requests an order + details (GET api/Orders/123) to open in a fancy WPF OrderDetailsEditView.xaml and changes in a grid an "amount" field on an orderline and presses "save" to save the modified order, the whole Order-entity object graph would be serialized and send back to the api (PUT api/Orders/123).

This seems like a bit of overhead. Is there a better way to send only the modified entities back to the server ? Or for instance "cut off" some parts of the object graph, like the "products" entities, those might be prefetched when requesting the Order-details (because for instance a productname should be displayed in an orderline in a grid), but I don't want to serialize those Product-entities and send back to the server when just modifiyng some amount on an orderline, or some remark on the order-entity itself.

Thanks for any remarks !

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Aug-2015 08:07:59   

As I see it, this is more a problem to be solved in your client scope. You should cut-off the graph before serializing it and send it to the server.

David Elizondo | LLBLGen Support Team
HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 19-Aug-2015 10:42:47   

Still struggling with this one.

Following Frans's blog on WebAPI, the serialization to JSON objects works well, but on every entity the "IsNew" is set to true af deserialization, also for exisiting entities that have Id != 0 .. am I overlooking something ? If I save an update entity in the backend (in a PUT request, deserializing the entity that came back from the client), the WebAPI method just aborts (no exeception or anything) ... i have to manually set "IsNew= false" and then it saves correctly