tags:

views:

82

answers:

1

I have a progress bar on a UI I would like to update when a record gets inserted into my database. I have done this before when I only had a UI Tier and a Business Tier with no problems. But I am now breaking my code into a UI Tier, Business Tier, and Data Tier and I can't figure how to properly call my OnPropertyChangedEvent in my Data Tier from my business tier and get my UI to update. I am just starting to get familiar with delegates so any advice would be helpful.

Thanks!

+1  A: 

Typicaly you don't want the Data tier to have any knowledge of the business tier, i.e you want the dependencies flowing down (using abstractions) UI --> BLL --> DAL. If you want to get notifications from the data tier when a record is inserted, you could expose events such as OnBeforeInsert, OnAfterInsert,OnBeforeUpdate,OnAfterUpdate etc. in the data tier that the business tier subscribes to. Invoke the event before and after the DB operations, you could create a custom EventArgs class with whatever data you need to get to, which you can then instantiate and pass along when you invoke the event. The UI/BLL can then use this to show progress or do whatever it deems fit.

Abhijeet Patel
Oh I didn't even know those Events existed. How do you expose these?
Nathan
I believe that if you are using LINQ2SQL or the Entity Framework these events are exposed out of the box for you. If you are writing your own data access layer then you would need to write these events yourself. In either case the client(in this case the business logic) would then subscribe to these events so that it is notified when an Insert/Update etc. happens, the Business layer can then do any processing it wants in the event handler. Additionally you an also write events for the business layer classes which in turn can "bubble" up events to the UI layer.
Abhijeet Patel
Thanks for info.
Nathan