Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day fellow coders, I recently started to build n-tier applications (Presentation Layer, Business Layer and Data Access Layer) in C# and all is well. Until I came to data access layer, at the moment my DAL is static in the sense that for each table in my database I have a data access layer with the different select, update, delete and insert statements for that table for example I have a client data access layer and an order data access layer. Now the question I have is how to make a data access layer dynamic in other words only to use one dynamic data access layer which contains dynamic methods all the business layers can use to select,insert,update or delete data. Put simply I wish to use only one DAL instead of multiple for each table in the database. The purpose is for re-use ability. Please try to help. I would appreciate it!
Posted

Normal answer is that that isn't a good idea.

If you have a rather simple application then you can get by with nothing more than CRUD procs.

And with a simple application then it is much easier to debug, understand and maintain. So there isn't any point to attempt to drive to a generic layer.

In a more complex application there are more complex operations. Thus procs besides CRUD will be needed. The increased complexity is across the board and that extends to maintenance. A generic layer is thus a better solution as it is is more likely, at least to some degree, to reduce overall maintenance costs (trading complexity in one area for complexity in another.)

Now if you want to use another approach to learn how to do it and it seems likely that such an approach would benefit the company (or perhaps that is not a factor) then you might investigate alternatives.

If and only if that is the case then you might want to look at nHibernate.
 
Share this answer
 
Comments
TheeStudent 17-Aug-11 1:22am    
Thanks for the reply first of all! I understand what u mean that simplicity keeps it easier to understand and use. Hence I would still like to try and implement a generic layer. Do you maybe have an example or reference on how to code this? I know one why is to use sql parameters, but I was told that its the old way and datasets have replaced sql parameters.
Espen Harlinn 17-Aug-11 18:30pm    
Don't believe everything you are told - datasets are just an expensive wrapper around the connection/command/reader stuff - It has it's uses - like providing the "generic" functionality you are thinking about - and it's widely supported - but like most generic stuff it makes code harder to understand by other developers.
Espen Harlinn 17-Aug-11 18:31pm    
Good reply, my 5
"Hence"?

Your second statement does not follow from the first.
It is NOT easier to understand a generic layer.

Other than that I mentioned "nHibernate" which an open source generic solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900