StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Best practice to Enumerate BO to delete...Expand / Collapse
Author
Message
Posted 06/19/2009 1:21:18 PM


StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Yesterday @ 9:52:36 PM
Posts: 1,653, Visits: 9,543
Hi guys,

I have a BO filtered with records that needs to be deleted from the database, I am trying to use BO.GetEnumerable() to go trough each record and delete it, but of course the once it is deleted, it is removed from the currentview and mess the CurrentRowIndex, here is the code I tried:

Me.BizTransactionItemsStock1.Filter = "Flag_DeletedRecord = True"
For Each StockBO As bizTransactionItemsStock In Me.BizTransactionItemsStock1.GetEnumerable()
StockBO.DeleteCurrentRow(True)
Next


Then I simply decided to use another For..EndFor so the CurrentRowIndex will have no effect like this:

Me.BizTransactionItemsStock1.Filter = "Flag_DeletedRecord = True"
Dim lnReccount As Integer = Me.BizTransactionItemsStock1.Count
If lnReccount > 0 Then
For i As Integer = 1 To lnReccount
Me.BizTransactionItemsStock1.DeleteCurrentRow(True)
Next
End If


This code is working for me, but I want to make sure there is not better way to handle this? of course, after this, a BO.Save() will actually delete the records from the database.

Thanks!

P.S.
To all developers, be aware of the BO.Filter and BO.Sort effects which will immediately remove any record which does to comply with the Filter and for the Sort, it may mess your CurrentRowIndex as well while trying to enumerate the BO. These are very powerful features , but also very tricky

Edhy Rijo
(Using VB.Net 2010/SQL Server 2008)
Post #23627
Posted 06/19/2009 2:08:42 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 3:16:36 PM
Posts: 411, Visits: 2,813
Edhy,

If you loop through backwards and delete then current index won't get out of whack.

 

For i As Integer = MyBO.Count - 1 To 0 Step -1

 If MyBO.somefield = Something Then

Delete

Endif

Next

Post #23628
Posted 06/19/2009 2:22:29 PM


StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Yesterday @ 9:52:36 PM
Posts: 1,653, Visits: 9,543
Hi Paul,

Thanks, I did not even consider that option and sure it does make sense. I will test it.

Edhy Rijo
(Using VB.Net 2010/SQL Server 2008)
Post #23629
Posted 10/12/2009 10:35:30 PM


StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Yesterday @ 9:52:36 PM
Posts: 1,653, Visits: 9,543
Paul Chase (06/19/2009)
Edhy, if you loop through backwards and delete then current index won't get out of whack.


Hi Paul,

Just to let you know that today I came across a situation where your suggestion fitted perfectly.

Thanks again for sharing.

Edhy Rijo
(Using VB.Net 2010/SQL Server 2008)
Post #24897
Posted 10/13/2009 6:15:25 AM
StrataFrame Team Member

StrataFrame Team MemberStrataFrame Team MemberStrataFrame Team MemberStrataFrame Team MemberStrataFrame Team MemberStrataFrame Team MemberStrataFrame Team MemberStrataFrame Team Member

Group: StrataFrame Developers
Last Login: 04/11/2010 6:13:14 AM
Posts: 43, Visits: 208
Hi Edhy,

   I used this with a little test database containing a Flag_DeletedRecord column, and it worked fine:

{BO1.Filter = "Flag_DeletedRecord = True";
 if (BO1.Count > 0) { do { BO1.DeleteCurrentRow(); } while (BO1.Count > 0); }
     BO1.Save(); BO1.Filter = "";}

   I hope this relates to what you're doing. Good seeing your name again after all these years...

Les

Post #24900
Posted 10/13/2009 7:38:27 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 10:14:22 PM
Posts: 464, Visits: 18,997
Les !!

How nice to see you here after all these years. I believe the last time I saw you I was manning the F1 booth near yours at ... Ft. Lauderdale? Palm Springs? I remember Ceil was running around taking pictures. ( man I miss her)

Anyway, welcome to Strataframe. I think you are going to love it and I know your contribution to this community will be very welcome. If you've not yet had the opportunity to meet the Taylor family I know you will enjoy each other.

There is a lot of real-world pragmatism and appreciation of "Microsoft realities" built into this framework and I've found it invaluable in getting very productive in .NET.

Hope we see a lot of you here.

( for the benefit of non-Fox lurkers who may not know him - Les is one of the best known authors, teachers and speakers in the Foxpro world as well as being one of the most colorful and interesting characters in anybody's world )
Post #24902
Posted 10/13/2009 8:48:11 AM


StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Yesterday @ 9:52:36 PM
Posts: 1,653, Visits: 9,543
Hi Les,

Glad to see you in the StrataFrame community, it will be very positive for all.

About your sample approach, it is interesting, thanks, I will test it with my project.

Edhy Rijo
(Using VB.Net 2010/SQL Server 2008)
Post #24903
Posted 10/13/2009 1:41:44 PM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Yesterday @ 12:18:50 PM
Posts: 118, Visits: 2,820
Hi Les,

glad to see you here!

Post #24917
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Trent L. Taylor, Steve L. Taylor, Dustin Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 8:33am

Powered by InstantForum.NET v4.1.4 © 2010
Execution: 0.094. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.