locked
DAL - Best .NET method to use? RRS feed

  • Question

  • User1123965013 posted

    I have been investigating the different ways i can access data from my SQL DB and i'm looking for some opinions on the best method to apopt for the creation of my Data Access Layer (DAL) for an ecommerce website.

    My SQL database contains all the usual tables for this type of website such as users, products, orders, orderdetails, and more... so it is important to have a solid DAL foundation for me to work on.

    The methods so far under consideration appear to be:

    1) Manually Create my own Classes (seems like a fair bit of manual and technical work).

    2) Create strongly typed Datasets (using GUI for SQL tables, PK's, FK's, SQL specific queries).

    3) Entity Framework

    4) SQL Datasource direct into the webpages.

    I am looking for that perfect combination of less programming required but flexibility for query and schema changes and additions in the future.

    At present i am tending towards Option 2). Can anyone give me a better reason to choose one of the other methods or perhaps a better suggestion?

    Also, i am going to have to create the Business Logic Layer once my DAL is set, so again which method would be best for that?

    Thoughts?

    Tuesday, February 16, 2010 12:19 AM

Answers

  • User-952121411 posted

    I am not sure of your experience level with .NET or your timeline for completing the project, but I would use a combination between #1 and the concept behind #2, just not using DataSets.  I would bring the data back from the database and then place the values into custom objects that map similarly to your table structure (not exact obviously), like Products, Orders, Customer, etc.  Then you create a strongly typed list of objects using the List(T) Class in .NET.  This will give you the strongly typed nature you desire, but doesn't pigeon hole you to the System.Data.DataSet type in ADO.NET.  After all how many times has the data access method changed in .NET: DAO, RDO, ADO, ADO.NET, EF, ....  DataSets are by no means going away anytime soon because they are so powerful and widely used, but probably better to work with custom built objects rather than the DataSet type specifically.  If you have not used lists of objects in .NET before, take a look to the following quick read which should help get you started.

    .NET Object Collections Using Generics 101:

    http://allen-conway-dotnet.blogspot.com/2009/11/net-object-collections-using-generics.html

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 16, 2010 10:15 AM

All replies

  • User-1618234021 posted

    Hi

    On top of all, if you will be having Business Logic Layer later on, it is strongly advised that you should go for option (1) for most of the DAL code. Because it is much easier and flexible to communicate b/w the 2 layers when you are manually handling them

    On some very simple web pages you can also use option (4). 

    On the whole the mixture of option 1 and option 4 will be good enough.

    Tuesday, February 16, 2010 12:55 AM
  • User-952121411 posted

    I am not sure of your experience level with .NET or your timeline for completing the project, but I would use a combination between #1 and the concept behind #2, just not using DataSets.  I would bring the data back from the database and then place the values into custom objects that map similarly to your table structure (not exact obviously), like Products, Orders, Customer, etc.  Then you create a strongly typed list of objects using the List(T) Class in .NET.  This will give you the strongly typed nature you desire, but doesn't pigeon hole you to the System.Data.DataSet type in ADO.NET.  After all how many times has the data access method changed in .NET: DAO, RDO, ADO, ADO.NET, EF, ....  DataSets are by no means going away anytime soon because they are so powerful and widely used, but probably better to work with custom built objects rather than the DataSet type specifically.  If you have not used lists of objects in .NET before, take a look to the following quick read which should help get you started.

    .NET Object Collections Using Generics 101:

    http://allen-conway-dotnet.blogspot.com/2009/11/net-object-collections-using-generics.html

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 16, 2010 10:15 AM
  • User1123965013 posted

     Thanks Allen. Excellent advice.

    Sounds like the vote is on using custom classes as the best approach for ease & adaptability for future changes. 

    The class concept of creating my own custom objects, properties & methods appeals to me as i can grow my own library over time.

    After reading your blob i understand now the List (T) class can help with typed data and can effectively replace the #2 Dataset option.

    My real hurdle to this ecommerce website was going to be the shopping cart object, but now i can see the real power in using classes especially for this. All my methods can also be set in one location.

     

     

    Tuesday, February 16, 2010 5:39 PM
  • User869128136 posted

    Hi, 

    Probably you refer to the Active Record DAL pattern as Custom classes approach.

    Probably it's good cause it does't depends on concrete frameworks. 

    But i would consider using ORM mappers as faster way to create DAL. Typical ORM:

    Entity framework,

    NHibernate

    Thursday, February 18, 2010 3:57 PM