Multiple DataPortal_Update methods in single class?

Multiple DataPortal_Update methods in single class?

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


andrewrajcoomar posted on Wednesday, August 12, 2009

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 

 

JoeFallon1 replied on Wednesday, August 12, 2009

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

 

 

JonnyBee replied on Thursday, August 13, 2009

Hi,

You can have several DataPortal_Update methods so long as they have a diffent signarture (parameters).

Normally you would send your BO as parameter and you can ask FieldManager to check each field for IsDirty and only update your database with the changed fields.

For other types of (partial) updates (ex change status on order) I would create Command objects and call them from my BO (and not create multiple overloads on the DataPortal_Update method in my BO).

/jonnybee

Marjon1 replied on Thursday, August 13, 2009

If this was a root level object, then how would any specialized DataPortal_Update() be called as part of the Save() method? I don't think root level objects work that may. Or you would need some form of branching logic within the standard to call your own methods. It's not possible to call DataPortal.Update(Of T) with any parameter other than an object of T

At a child level with the field manager this makes sense, therefore having this really only applies to Child_Update() methods. (See comment by /jonnybee)

Just putting this out there so people don't get confused between where this really applies.
Should any of the above be wrong, please feel free to correct me.

andrewrajcoomar replied on Thursday, August 13, 2009

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

RockfordLhotka replied on Thursday, August 13, 2009

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

andrewrajcoomar replied on Friday, August 14, 2009

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