partial Updates

partial Updates

Old forum URL: forums.lhotka.net/forums/t/4724.aspx


Ashraf Ali posted on Monday, April 21, 2008

Hi,

Has anyone done partial updates with CSLA, say, If I have a class Customer, the update method in Dataportal_update will update everything in Customer, but there are cases where I need to update say just the lastname of customer. What will be the best approach? should I inherit from the Customer class creating a new class, Should I use commandBase object?

Thanks

Ash

sergeyb replied on Monday, April 21, 2008

Technically, you should create a totally separate class in this case because most of your properties would be read-only, only last name is writable.

 

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: Ashraf Ali [mailto:cslanet@lhotka.net]
Sent: Monday, April 21, 2008 4:28 PM
To: Sergey Barskiy
Subject: [CSLA .NET] partial Updates

 

Hi,

Has anyone done partial updates with CSLA, say, If I have a class Customer, the update method in Dataportal_update will update everything in Customer, but there are cases where I need to update say just the lastname of customer. What will be the best approach? should I inherit from the Customer class creating a new class, Should I use commandBase object?

Thanks

Ash



JoeFallon1 replied on Tuesday, April 22, 2008

Ash,

I think a lot of it depends on the case in hand. You don't give us enough information to make a good recommendation.

If you are on a screen where you already have a complete Customer BO in hand, then I would add a new factory method to the customer class (like SaveNameOnly) and then branch on that method name in the DataPortal code so that you only save the 1 field.

If you do NOT already have a Customer BO handy, then I would use a Command Object inside of the main BO for the current screen.

Joe

 

Ashraf Ali replied on Tuesday, April 22, 2008

Joe,
I am on a screen where I dont have any Customer object, I need to loop through all the customer objects and update their last name only, Now I do have full Customer collection objects (not in the screen but in the project), but I thought I should use something different just for updating the name.

Thanks
Ash

Cosmin replied on Tuesday, April 22, 2008

Ashraf,

Check the Project class in the ProjectTracker application. Especially the ExistsCommand inner class.
Basically you need to create a new class CustomerNameUpdater that inherits from CommandBase. In the DataPortal_Execute you do the real update.

The purpose of CommandBase is to allow you to do quick things, like updating order status or customer name in your case, in the database without loading any business object.

Hope this helps,
Cosmin

Ashraf Ali replied on Tuesday, April 22, 2008

Cosmin,
Thats exactly I am doing, I had to create 8 different classes this morning :) ( and the customer object I was using it as an example). I still wonder if there might be an easy solution then writing so many classes.
Thanks for your reply,
Ash

Justin replied on Wednesday, April 23, 2008

We are looking at a way to do this also, it not so much that there is a usecase for say just updating lastname, it's that a user may pull up a customer object which they might update anything but they only modify lastname and this is all we want to update in the database for performance but more importantly auditing purposes.

Bottom line it seems you will have to implement an internal mechanism for tracking isdirty on a field by field basis, probably by hooking into PropertyHasChanged, then when Dataportal_Update is called examining which fields are dirty and creating a dynamic SQL statement(if your saving to a SQL server) to update only the changed ones. We are also looking a overriding our XML serializer so only changed  fields are sent through the web service transport as well.

Justin

Copyright (c) Marimer LLC