Hello,
I was wondering if it's possible to have multiple dataportal_update methods in a single class to facilitate partial updates of the class. Can the update method perhaps have different signatures using the criteria class? Or is the only way possible, is to have conditional logic in the method that then class update1, update2 or update3?
This is a very common situation for me, where I have to update just one or two columns on the table.
Greatly appreciate any help on this.
Using VS2008 with CSLA.Net 3.5.
Thanks,
Andrew
You can have it either way - or both if you want.
The signatures of each DataPortal_Update must be different from each other. Then the framework will locate the correct version based on its signature. So you need to use different criteria objects if you want different DataPortal_Update methods.
Alternatively you can always go to the one DP_Update and then branch based on the type of CriteriaObject. If I use the same criteria object many times then I also add a MethodName As String to the criteria and do further branches by MethodName. (It is obviously filled in with the name of the method that calls DP.Update.)
That way you can branch as much as you need to do whatever updates you require.
Joe
Thanks for your responses.
Here's a summary of what I am trying to do:
I have a gridview bound to a BOReadOnlyList. The list contains "to-be-validated" data that has passed basic validation and has been imported into the db. Now, when the user clicks the "Validate" button, I walk the gridrows and validate the fields against specific business rules. If a row fails validation, I want to update the BO with two columns, Status and Message. By the way, I could iterate thru the List for each info object, but as I walk the grid I also use the opportunity to provide visual feedback (row coloring) to the user.
What I am doing is, if the row fails validation, I pass the PK as parm to the BO.GetMyObject method and return a complete object. I then set the properties for those two values and call the BO.Save method.
This approach isn't efficient as I am hitting the db twice for a row, once for the Fetch and then for the Update, plus I am doing this for each row in the grid :-(.
I would like to use the Criteria object to specify branching in my Update method, or just to specify a different signature for each Update method. However, I am challenged with how to implement. I am thinking a partial object would fail the Validation Rules in the class. More importantly, how do I create the partial object; I can't use NewMyObject, as that would certainly fail validations.
So the issue is, how to create the object that I want to perform partial updates on, and how do I call the Update?
I'd really like even so psuedo-code of an implementation.
Thanks,
Andrew
You should be aware that the read-only base classes (like ReadOnlyListBase) don't have any update methods, because they are read-only.
If you want to update data you should be using an editable base class and editable stereotype.
If you want to do the update (and associated server-side processing) in a batch then you'd use BusinessListBase. If you want to do the update per-row you'd use EditableRootListBase - though that is far less efficient for a scenario like you describe (enough that I suspect it wouldn't be acceptable).
If you really want to use a read-only list, then you'll need to have a command object that you send to the server to do the server-side processing and update - either on a per-row basis (highly inefficient) or to process a batch (much more efficient).
Rocky,
Thanks for your response.
I am using a ReadOnlyList and an EditableBase class. The ROL is bound to my grid. When I programatically validate a row in the list, I need to call a partial update on the table. This is where I am fetching the data into my editable base class object and then setting the properties I need to change. Then I call the Save on the editable base class. I believe this is highly inefficient, but I am not sure what other way I can do this. Am I understanding that I could return a BusinessListBase object, bind that to my grid, make my changes server side and then save the whole collection object as a batch?
Any pointers on how to implement - guess I need to break out the handbooks :-)
Thanks,
Andrew
Copyright (c) Marimer LLC