The best way to organize work with database [closed] The best way to organize work with database [closed] database database

The best way to organize work with database [closed]


Use a Object/Relation Mapper (ORM). My personal favorite is nhibernate. Use Entity Framework if you want a Microsoft product.

ORM's usually implement UnitOfWork and Repository patterns which makes it easier for you to handle database operations and follow the Single Responsibility Principle.

You also mentioned singletons. I would avoid them if possible. Have you tried to unit test a class that uses singletons? It's impossible unless the singleton is a proxy for the actual implementation. The easiest way to remove singletons is to invert dependencies by using dependecy injection. There are several containers available.


The recommended way to work with databases these days is through an ORM.

Look at nHibernate (community project) and Entity Framework (Microsoft provided) for some of the most popular choices for .NET, though there are many many more.

These are libraries that provide you with all the data access that you need, with some configuration needed.


The repository pattern is a very common way to structure your data-access logic.