Generic repository with SQL

Asked

Viewed 324 times

1

Seeing this question: Here

I wondered if it is possible/right to use a scheme like this in a project in which I do not use any framework for connection to a database.

I would like an example of the correct way to have a DAL layer in which to communicate with SQL SERVER.

I really need to have a method for all my interactions with the bank?

2 answers

3

It is not mandatory to use a layer only for database interaction. It goes a lot of the project you are developing.

For example, if you’re building a simple application, an To-Do List or a project with very few tables or entities, and you or someone for sure do not need to include new features in the future, do not see that it is necessary to waste time with the data layer.

On the other hand, if your project has the potential to grow (include new features, frequent changes, among others) I recommend looking with care, right at the beginning of the project, in a layer of repositories for your application, precisely to isolate the logic of the bank implementation business. This will make it much easier to evolve your application.

3


Yes, it is possible.

I gave an example of generic DAL here. In fact the idea is a DAL that looks a lot like a repository, since the basic operations are generated from the class passed to the common class. Other transactions can be written in classes derived from Comum.

However, it is important to say that this method is a bit long and it will take you some time to write operations that are not trivial (for example, a select with join, and the assembly of the objects to the layer that requested the data). Or even, in the worst of the worlds, you can work with the DataTable direct, which is the worst possible approach.

  • For a short project, it is best that I create a method for each operation, for each table?

  • 1

    @Felipe The example I have already set for you 4 methods per entity, saving you from having to implement selection, inclusion, updating and deletion for each entity of your project.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.