C# – the use of a persistence layer in any application

cnet

I have to create an application in which I am asked to create an persistence layer in the application. The application is in .net. I have created a business layer and a presentation layer but I don't know how and why I should create a persistence layer.

I googled and came to know that persistence layer is used for storing and retrieving data usually from a database.

Can anybody explain in detail?

Best Answer

the reason for you to build a DAL ( Data Access Layer ) or any other kind of intermediate layer between database engine and Business / Application logic, is that by adding this layer in the between you isolate the rest / upper layers of your application from the specific database engine / technology you are using right now.

This has several advantages, like easier migration to other storage engines, better encapsulation of database logic in a single layer ( easier to replace or modify later depending on how well you have designed your cross-layer interfaces etc...)

see my answer here, it is an example about ASP.NET MVC and EF but the structuring of solution and projects is actually technology independent: MVC3 and Entity Framework

Also read some articles to better understand this matter, for example: http://www.developerfusion.com/article/84492/net-and-data-persistence/