Tutorial :Data Access Layer in .net


I am designing an application where I want to reduce the burden on the developers for future for development. In this I have list of classes e.g-"User,Account,Permission and etc" now these classes are associated to the table in the database with the name of the class same as data table. I want my business layer to be robust so that in future whenever I add any more column to the data table I don't have to rewrite insert update and delete command just adding property to the class should do the job.

Any Idea how to do this?


What you are looking for is probably an ORM (Object-Relational Mapping) framework. The most popular ones for .NET includes Linq-to-SQL (or Entity Framework), NHibernate nad ActiveRecord. Using an ORM is considered a best practice for achieving a maintainable and robust Data Access Layer.

See a list of frameworks here.


What you're probably looking for is to implement an Object Relational Mapping (ORM) solution. Many ORM solutions help you maintain table and entity definitions and also create the appropriate queries for you.

Popular ORMs for the .Net Framework include NHibernate, the ADO Entity Framework and LINQ to SQL. Otherwise you could consider mapping your data model using templates (like using Codesmith, or the Net Tiers templates).

You could check out the answers to this question for more advice on picking an ORM solution, or you can just browse some ORM related questions tagged here.


I think what you are looking for is a Data Transfer Object. Here's an article that explains more about the DTO pattern.

Additionally, here's an article that explains how to implement a DTO with a Dataset. In your case, the Dataset would be replaced with your own Datalayer.


Picking an ORM solution is one way, additionally i would mention the upcoming Oslo.

For a more "traditional" approach i would take a look of Data Abstract.


Quite interesting reading about this topic is the Persitence Patterns article. It explains the most common and basic design patterns used for the Data Access. Also it discusses when the concrete DP might be more suitable than the other.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »