3

OK, as the title suggests I am designing a data access layer for a survey framework I am currently working on.

We all are familiar with the layered architecture notion, we try to achieve separation between the layers in a way that presentation layer can be hooked to any business layer, in the same way business layer can be wired to any Data access layer regardless of its implementation as long as it maintains the same interface (Same methods).

Now, after building the database using SQL Server, I am building the DAL using a DataSet (*.xsd) file and in this file I create the methods for each table adapter and the corresponding stored procedures in the database.

After working for a little while with the data set visual designer in Visual Studio I have noticed that I am aiming at providing a very flexible API that provides all the possible queries for the user in the form of methods. For example, I want to provide the user with methods that performs retrieval operations on the tables using any possible filter or with not filter, I also want the user to be able to delete rows using any column she/he wants as filter, also updating all/individual fields using any column he wants as a filter.

The way I have accomplished this primarily is by creating a method for every possible query whether it is DDL or DML. Now, when I think that I might made a mistake in a certain method or that I want to check the methods to make sure I did not miss anything while fast typing it seems like a pain because I have ended up with a ton of methods.

So, my question is: Is there another way for designing the data access layer so that it can be easy to refactor the methods and create them?

I hope I did not elaborate too much but I wanted to put you in the picture so I can get the correct answer, thanks in advance

3
  • 1
    Is there any reason for you not using .NET 3+ and working with Entity Framework? It makes things a whole lot easier when working with your Data Access layer. Oct 10, 2012 at 11:24
  • I am just not that experienced with EF even though it is easy. Will the EF product the table I had in mind in the database? Will I end up with the same database if I started by creating the classes?
    – Saleh Omar
    Oct 10, 2012 at 11:27
  • Yep, you could quite easily use EF and use a Repository, linking to any provider you like. This is a common practice now and I'd highly advise it. Oct 10, 2012 at 11:39

1 Answer 1

2

Well, you could use an ORM tool to provider a good data access layer. I mean it because with an ORM tool you will have support to most of populars databases as SQL Server, Oracle, MySQL, PostgreSql, etc.

Depending of wichi ORM tool you use, you do not have to write SQL statments, which means you will be less sensitive to error an query.

I recommend you to check a tool called NHibernate. With this ORM you can write queries using Linq and another one (more specific for NHibernate) called QueryOver. You will have a lot of flexibily to write dynamics queries. With an ORM tool you could implement a Repository Pattern and create methods and queries to get working data access.

So, when you use something like this, you will have the benefits of the Visual Studio like Refecting, because Linq, and QueryOver is strongly typed. But you will have HQL too, it like Sql Statment.

Check this article: Why I don't use DataSets

5
  • I am not writing any queries using the data set either. It is just that I have to create a method for each query which seems very repetitive not to mention the sheer number of methods I have ended up with.
    – Saleh Omar
    Oct 10, 2012 at 11:31
  • You could create a Generic Repository, look this: daniel.wertheim.se/2009/11/04/nhibernate-repository-pattern. With this you will have a lot a Generic Implementation and get it working. If you need something more specific, you would inherit from the Generic and implement on the base. And yes, you have to write an specific query to improve performance when it is necessary! Oct 10, 2012 at 11:35
  • if you still are not comfortable with ORM tools, I recommend you search on the MS Entity Framework (Code First). It is easy to implement and works very fine with Sql Server, by the way, NHibernate is a mature tool but the initial learning curve is more complicated. Oct 10, 2012 at 11:57
  • @FelipeOriani Is EF not an ORM tool? Oct 10, 2012 at 12:36
  • Yes, Entity Framework is a good ORM tool. I'm sorry, I think I expressed myself badly. I just want to say it is easier than NHibernate. Oct 10, 2012 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.