multiple update methods

multiple update methods

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


Skafa posted on Friday, October 06, 2006

In some cases i need to update a class partially. how would i do that? because there's only one dataportal_update method? or can you define multiple with different 'criteria' classes?  


Q Johnson replied on Friday, October 06, 2006

Can't you just populate each instance of the criteria class with different values depending on the update context?


From: Skafa [mailto:cslanet@lhotka.net]
Sent: Friday, October 06, 2006 8:36 AM
To: QJohnson@TeamNFP.com
Subject: [CSLA .NET] multiple update methods

In some cases i need to update a class partially. how would i do that? because there's only one dataportal_update method? or can you define multiple with different 'criteria' classes?  





ajj3085 replied on Friday, October 06, 2006

Yes, you can have as many Update methods as you want, as long as they are distinguished by different Criteria classes.

xal replied on Friday, October 06, 2006

No, I don't think that's right. Correct me if I'm wrong, but while this is true for fetch, create and delete scenarios, there's only one DataPortal_Update() and one DataPortal_Insert(). The dp will choose which one to call according to IsNew.

So insert and update have no criteria, they are called right after you call Save().
What you can do is have different methods that you can call from DataPortal_Update() depending on data that the object contains, like:

Protected Overrides Sub DataPortal_Update()
If mValue = 1 Then
    UpdateV1()
Else
    UpdateV2()
End If
End Sub



Andrés

ajj3085 replied on Friday, October 06, 2006

right... was typing faster than I was thinking.

Copyright (c) Marimer LLC