By Edhy Rijo - 5/19/2008
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)NextMe.PaymentScheduleBO1.Save()But the above code is not deleting all rows in the BO, so I must be missing something here.
|
By Keith Chisarik - 5/19/2008
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))
|
By Trent L. Taylor - 5/19/2008
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.
|
By Keith Chisarik - 5/19/2008
Great to know about TRUNCATE. Thanks.
|
By Edhy Rijo - 5/19/2008
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.
|
By Trent L. Taylor - 5/19/2008
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.
|
By Richard Keller - 5/19/2008
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
|
By Trent L. Taylor - 5/19/2008
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.
|
By Edhy Rijo - 5/19/2008
Thanks to all for the posting.I decided to use the following code in this particular case... Dim lnCount As Integer = Me.PaymentScheduleBO1.CountFor I = 0 To lnCount - 1 Me.PaymentScheduleBO1.DeleteCurrentRow(True)NextMe.PaymentScheduleBO1.Save() This is very fast and will only do one trip to the database to remove all deleted records.
|
By Trent L. Taylor - 5/21/2008
That is a good solution. You could also just do a while as well:Do While MyBo.Count > 0 MyBo.DeleteCurrentRow(True) End Do
|
By Edhy Rijo - 5/21/2008
Thanks you Trent,I am learning a lot every day. So far this project is coming out pretty good, and I fall in love with the new Enhanced ListView, those enhancements are really a time saver for developers and I am glad you incorporated them.  If possible please, let me know when will be the next beta release that will include the added property to handle the delete flag.
|
By Trent L. Taylor - 5/21/2008
Yeah, I plan on posting a new build soon...but I have the DDT torn up a little bit right now, so I need to get "Humpty Dumpty" put back together again before I post a new build . I am using it every day so it isn't necessarily the functionality, but rather the UI. The DDT is getting a face lift that will continue over the next several updates so that we can incorporate some new functionality that we have planned.
|
By Edhy Rijo - 5/21/2008
Thanks for the info.No rush on my part, so far I am using my temporary fix, so I can live with it until the next release. 
|