Search code examples
architecturedataset3-tier

Updating DataSet - in which layer?


I try to construct 3-tier application. In DAL I get data from database (No-SQL) to DataSets. In BLL I process this data if it is necessary. In PL I show appropriate data.

The question is: If data in database are still updating, and I need to have at once newest 'rows', should I update DataSet in BLL with some timer or somewhere else?


Solution

  • When you say "at once" I have to assume that your application is very eager on data... for that you should use a 4th layer between your DLL and BLL and called Cache.

    As it seams that you want things fast, and for fast things, you never call the database over and over, you call once and when there's an update, you clear the cache on that entity and next time your BLL asks the data, the cache is empty so it passes to the DAL to retrieve a new set of records, putting it in the cache for the next call.

    To be alert with updates you can do your own notification system, or simple implement the INotifyCollectionChanged interface...

    If you do not want to take all this trouble, when you send the new row to be changed, you already have the data, you can easily add it to the grid (or any colection object that you are using) with a simple

    DataTable dt = bll.ListAllEmployeesByCompanyId( 2 );
    dt.Rows.Insert(0, myNewRow);
    gv.DataSource = dt;
    

    You can easily create a nice UX by making a top border in that grid and make it yellow (as the data did not come from the database) and turn it into light green when the data come all from the database (and all is in sync) ...

    It's all up to your strategy, it's always down to the one and only question for every software we develop:

    Does the user really care about that awesome feature?

    Because, we developers tend to assume a lot, and sometimes, you do assume wrongly :)