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
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
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
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
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