StrataFrame Forum

Refreshing/Refilling a business object

http://forum.strataframe.net/Topic11743.aspx

By Andria Jensen - 9/27/2007

What's the best way to refresh the data in a business object?  I know you can just call the fill method over again, but I have a situation where this is not going to work.  I am in edit mode on my form, but I have a few un-editable values on the form which may change.  If the values update I want it to reflect on the form.  If I call the fill method, it will take it out of edit mode and back to idle.  Is there a good way to do this?  I thought about having one business object linked to the values I want to be able to refresh, and one that just links off to the editable values that won't refresh. When I need to refresh and they are in edit mode, I only refresh the one business object.  When in idle, it would refresh both.  Is this the right way of thinking about it??
By Peter Denton - 9/27/2007

G'day

To find out if you need to refresh you could use the ReceiveQueryNotifications method on the BO. Here's a snippet from the Documentation:

ReceiveQueryNotifications

The ReceiveQueryNotifications property determines whether a System.Data.SqlClient.SqlDependency will set to listen for Query Notifications that are registered on commands executed through FillDataTable(). When notifications are received, the ServerDataChanged method is raised allowing you to repopulate the business object due to changes within the server's data.

Note: To use Query Notifications, you must adhere to the following requirements:
  • SQL Server 2005 only
  • Properly formatted queries - Queries must follow the rules for a proper Indexed View query. See the Microsoft Developer's Guide for more information.
  • Enable the broker service (ALTER DATABASE [database] SET ENABLE_BROKER) on the database.

 

Once you've determined that you need to refresh perhaps you could

1. If necessary save the current changes

if MyBO.IsDirty then MyBO.Save

2. Determine which row in the table you're in

Dim MyRow as Integer = MyBO.CurrentRowIndex

3. Refill the BO by whatever means

4. Get back to where you were

MyBO.Navigate(MicroFour.StrataFrame.Business.BusinessNavigationDirection.Absolute, MyRow)

5. Get back into edit mode

MyBO.Edit()

Hope this helps. I haven't used the ReceiveQueryNotifications property, but I read about it some time ago and thought it might be useful.

Peter

By Trent L. Taylor - 9/28/2007

Andria,

Peter has a good idea and this is the purpose of a query notification.  But the one thing that would happen is that when you receive the query notification you will still have to call a Fill method of some kind.  What I would do, as you had mentioned, is create a separate instance of a BO and call the Fill on that BO.  Then if records are returned, you can filter out any duplicate records or records that have been modified on your edit BO.  Once you have the filter on the second BO the way you like it, call the CopyDataFrom method on the primary BO and pass it eh secondary BO and use the AppendFromDefaultView option.  This would probably be the best solution for what you are trying to accomplish.

By Andria Jensen - 9/28/2007

Well, sorry to rain on the parade but I can't use SQL 2005 specific methods.  Our application has to stay database neutral so that we can support Oracle and SQL.  Thanks for the answers though. 
By Andria Jensen - 9/28/2007

I'm going to attempt to try what Trent has suggested.  I think I follow, but I may get stuck at some point so expect to see me back here asking another question BigGrin
By Trent L. Taylor - 9/28/2007

Sounds good, Andria. Smile Let me know if you need more details.