Datasets as the DAL?

I was wondering if using datasets/adapters/datatables is a good way to manage my data access layer, or if I should keeping using this generic database library one of my friend wrote.

Thanks,

John




Answer this question

Datasets as the DAL?

  • Swarnima

    The decision should most likely be determined by the type of application you are building, and where it will run.

    Using data adapters / datasets / data tables can be quite fast to code, but incur a larger memory / CPU footprint than say a data reader. They can also create a situation where SQL changes could cause havoc in your application if the changes are not pushed throughout the rest of the application.

    Also, there can be serialization / deserialization of the dataset on each side of the DB call if these are on separate machines. That means every property and method is iterated over, and checked, etc... If you look at the object viewer for the dataset's Meta data, you will see this largess... One more note, data tables are not serializable in themselves, so this would be another argument for data readers.

    Additionally, you will then need to look into your dataset for any data of interest.

    As for the DB library you are currently using, if it gives you back a dataset/data table, your still in the same boat. If this is the case, consider using the Microsoft.ApplicationBlocks.Data class library. While its the same dataset issue you are questioning, at least you are using something that will continue to be improved with the technology.

    In conclusion, if you have an object model (or even a few classes), then you would most likely want to use a data reader and populate your object from the reader. This will minimize the amount of data access related code that propagates through out your application and centralize it in your business layer.



  • Venkat708

    Well, since I don't know anything about the "generic database library" your friend wrote - I can't comment about it

    There are two major schools of thoughts when it comes to business logic.

    There are those that favor domain driven desing (see http://domaindrivendesign.org/book/) and those that favor data centric approach .

    Datasets fit the second approach better (though there can also be useful in reporting scenarios when using DDD), where as for DDD one usually use an Object Relational Mapper (such as NHibernate, NPersist, Wilson O/R etc. )

    Arnon



  • Ayal91

    All depends, datasets are like BD in memory, but construct it is quite long. You should use datareaders for readonly data. It should improve performance drastically.

    Perhaps you could consider nhibernate or something, just to put more doubts :)



  • ILoveMFC

    Topmcsd wrote:

    PS: DDD is not applicable to DAL. DAL and DDD are two different levels of abstraction. DAL deals with data, DDD deals with data+domain logic.

    If you are practicing DDD you would probably want to seperate the Domain object from the data access (Single Resposibility Principle). The DAL is an adaptor that lets you format the Domain object to storage (a.k.a. Hexagonal Architecture)

    Arnon



  • Cynicszm

    I am in complete agreement with Arnon.

    Another important part of the decision should be based around the skill set of the development team. If your development team is not strong with OOAD then DDD is probably the wrong way to go. Let me tell you there is NOTHING worse than a poorly implemented domain model :D

    Requirements also go a long way towards choosing an approach ... If this is code is for a small system ... often times the problems DDD helps solve are not too big of a deal (i.e. code duplication) if you only have 3000 lines of code total and could redo the entire app in a week or two ... isolating yourself from change is probably not a very good investment (chances are the application will never become a maintenance nightmare, and if it does it can simply be re-written.

    Often times delivery schedules have alot to do with the choice as well ...

    Cheers,

    Greg


  • Antigen

    DataSet (in addition to scalar types; int string etc) would be an appropriate type to return from a DAL:

    1. It is provider neutral, so your could change the underlying provider without affecting the consumer.
    2. DataSets works well with quick and dirty solutions where you want to bind UI controls with less work.

    PS: DDD is not applicable to DAL. DAL and DDD are two different levels of abstraction. DAL deals with data, DDD deals with data+domain logic.

    Thomas




  • Datasets as the DAL?