Proper user of StrataFrame BO's


Author
Message
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
yes, the using blocks can be very helpful to make sure that you don't forget to call Dispose() when you're done with the object.  Any object that you declare in the using block's header has to implement IDisposable. 

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().

Scott
Scott
StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)
Group: Forum Members
Posts: 176, Visits: 1.5K
Good to know.  Didn't know about the using statement,  will look into that.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You could also use the GetDataTable() methods of the business objects to get a raw DataTable that you can work with that does not require the CurrentDataTable to be changed, but then you lose the ability to use the strong-typed properties of the business object.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Business objects have a low enough overhead that it is generally best to just create a local business object reference and work with it... just make sure to dispose of it at the end, so either use a "using" block or call Dispose() on the business object once you're done.

using (BOType mybo = new BOType())
{
    //-- Work with the bo here
} //-- bo gets automatically disposed when this block exits

Scott
Scott
StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)
Group: Forum Members
Posts: 176, Visits: 1.5K
This is a simple question but kind of difficult to explain.  I usually have various Fill methods on each of my BO's.  I often find that the custom methods that I write for the BO's, like for verifying data, could be much simpler if I just used one of the Fill methods and processed the records that are returned with the BO's MoveFirst() and MoveNext() methods,  the problem is that if I use a Fill method the current datatable would be overwritten.  I would imaging that the proper thing to do would be to have the method be completely self contained and not have a requirement that the currentdatatable be filled with the record that needs to be deleted.  How should this situation be handled, I was thinking of creating a datatable and coping the BO's current datatable then when the process is done restoreing the current datatable from the local copy.  Or the other solution would be to create a local BO and call its Fill method and process that way.  I was just wondering what kind of overhead each method involves and how you are recommending it be handled.

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?Hehe

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