Here is a simple example of a current situation. I have coded some delete rules in the Before_Delete event of the BO. Calling the DeleteByPrimaryKey does not fire the Before_Delete event, (makes sense, there is no datatable) so what I figured I would do is call the FillByPrimaryKey, call DeleteCurrentRow and process it that way. By calling the FillByPrimaryKey I am replacing the CurrentDataTable so I used a temp datatable object and restored the currentdatatable once processing was complete.
Help... am I just still not fully understanding .Net and how things need to be done?
using (BOType mybo = new BOType()){ //-- Work with the bo here} //-- bo gets automatically disposed when this block exits
Of course, when the garbage collector cleans up an object reference, it will dispose of it as well, but if there's an object reference still alive pointing to a business object, it will never get garbage collected, so it's best to explicitly call Dispose().