How to delete all records in a BO?


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi,

I have a a BO with related records and at some point I would like to delete all records in the BO pretty much like a VFP DELETE ALL or ZAP, how to do this?

I have tried using the BO's GetEnumerable() I saw in thread like this:

For Each bo As IBS_BOL.PaymentScheduleBO In Me.PaymentScheduleBO1.GetEnumerable()

     bo.DeleteCurrentRow(True)

Next

Me.PaymentScheduleBO1.Save()

But the above code is not deleting all rows in the BO, so I must be missing something here.

Edhy Rijo

Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
I had to do this and with many records in the BO it was slow (ZAP was awesome!!) so I did the delete via a stored procedure on the server (if your using SQL/DB2/Oracle/etc).

MicroFour.StrataFrame.Data.DataBasics.DataSources("").ExecuteStoredProcedure("rentitems_deleteitemsfororder", MicroFour.StrataFrame.Data.DbCommandExecutionType.ExecuteNonQuery, New SqlClient.SqlParameter("@ordnum", Me.BO_Orders.ordernum))



Keith Chisarik
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
You can do this with SQL Server, DB2, etc.  Just call a truncate on a table.  Create a method on the BO that is called "DeleteAll" or something along those lines, then TRUNCATE the table.  This is akin to the VFP "ZAP" except far more efficient.

TRUNCATE TABLE MyTable

Note: This will delete ALL records within the table.  That is the same thing a ZAP used to do.  If you want to delete within a certain crtiera, then just create a command or a sproc (as Keith mentioned) to delete within that group or records.

Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
Great to know about TRUNCATE. Thanks.

Keith Chisarik
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent, Keith,

Thanks for the recommendations, I am sure will use them.

In this case I am dealing with a few records, less than 12, and since I already have a BO with those 12 records shown on a list, I was looking for an easy way to get rid of those 12 records in a single step. 

I could implement any of your suggestions by creating a method in the BO to delete those records using the Forein key of the parent, but wanted to know if there was a better way to handle this.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
You can't change the contents of an enumeration...that is just .NET.  The reason you don't flat out get an exception when using the GetEnumerable is because the GetEnumerable returns unique instances of the BO...so even though you are changing the collection it is somewhat wrapped...but you will never get the records deleted.  But you can delete a lot of different ways, create an array of the PKs to delete and then enumerate that collection, create a shared method to delete for you, etc.  At some point we may add another overload to the BO that allows you to pass a "WhereClause" like the Seek method for a delete.  But for now those are some options.
Richard Keller
Richard Keller
StrataFrame User (174 reputation)StrataFrame User (174 reputation)StrataFrame User (174 reputation)StrataFrame User (174 reputation)StrataFrame User (174 reputation)StrataFrame User (174 reputation)StrataFrame User (174 reputation)StrataFrame User (174 reputation)StrataFrame User (174 reputation)
Group: Forum Members
Posts: 84, Visits: 324
Be careful with using Truncate.  It is handled differently in Log Operations.   If the table has a FOREIGN KEY constraint you cannot use truncate.  In addition, no Triggers will be fired as it is a non-logged operation.   I generally frown on the use of Truncate in any operational code for those two reasons.

Richard

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
We never use TRUNCATE in code either...except when the table truly needs to be cleared out and reset, and which time the code should accomodate this.  The context of this post is more in regards to the replacement method of ZAP in FoxPro for a similar method in SQL Server.  This would be the method in this case.
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Thanks to all for the posting.

I decided to use the following code in this particular case...

Dim lnCount As Integer = Me.PaymentScheduleBO1.Count

For I = 0 To lnCount - 1

     Me.PaymentScheduleBO1.DeleteCurrentRow(True)

Next

Me.PaymentScheduleBO1.Save()

This is very fast and will only do one trip to the database to remove all deleted records.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
That is a good solution.  You could also just do a while as well:

Do While MyBo.Count > 0
     MyBo.DeleteCurrentRow(True)
End Do

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search