What is the best approach to create a DAL?

I want to create the perfect custom DAL class (data abstraction layer) for use with all my projects.

I searched the Internet and found some examples for this, but I never know which one is best suited.

Do it [Attributes] ? Or use <Generics> or something else?

So please just give me a head line and I will go from there.

Thanks again and forgive me for the language.

+4
source share
9 answers

The best approach:

Do not do this yourself , unless for an academic research project or you are not going to create an ORM for business delivery.

First try using dozens of existing ORM solutions. (Entity infrastructure, subsonic, nhibernate, etc. Etc.). They all have their quirks and limitations mixed with tons of awesomeness.

ORM is incredibly difficult to get the right and huge start.

A bit connected and for money: http://wekeroad.com/2009/06/11/youre-not-your-data-access/

+6
source

Just make sure you:

  • Always use stored procedures
  • Never use stored procedures
  • Use stored procedures sometimes
  • Use nHibernate
  • Using SubSonic
  • Use Entity Framework
  • Write your own
  • Never write yourself
  • Use POCO
  • Use ActiveRecord
  • Use IRepository
  • Always do what Fowler says
  • Never do what Fowler says.
  • Do not use Linq for SQL, it is dead
  • Use Linq for SQL, it is no longer dead

Do it all and everything will be fine.

+10
source
+5
source

If you are a starter, I would recommend using SubSonic (especially if you are in web development).

+4
source

like one of the ones mentioned, do not try to implement the ORM tool yourself, many of them are freely available. But the DAL is not an ORM tool, the ORM tool will be used in your DAL. DAL is intended only to hide the logic of accessing data from the rest of your application in order to have a more convenient solution. As a result, you can also have normal SQL i statements. your DAO class. What you should pay attention to when creating your DAL is to separate it as much as possible from other applications / other layers. This can be achieved by coding interfaces and using dependency injection. Spring is a great help here (given your Java program). In addition, there is not much magic when building such a layer.

+1
source

Definitely do not write your own persistence manager. You must use Object-Relational Mapper (ORM) if you want to start with a class structure, and ORM generates SQL table structures for you, or use SQL Mapper if you want to start with SQL tables and want your classes to represent table rows.

I had a lot of experience using iBatis SQL Mapper, and many people like Hibernate for ORM (although there is a learning curve).

Martin Fowler describes some good approaches to writing data access layers in Enterprise Application Architecture Templates (here catalog ).

For example, iBatis for .NET uses the Fowler Table Data Gateway template. In iBatis, you specify the Data Data Gateway objects in XML. Each gateway typically controls access to a single SQL table, although you can also perform operations on multiple tables. The gateway consists of SQL statements, each of which is wrapped in XML. Each SELECT returns one or more row objects, which are just a set of attributes, as well as getter and setter methods (in .NET they are called POCOs or PONOs, ordinary C # objects, or ordinary .NET.NET objects). Each INSERT or UPDATE accepts POCO as its input. It seemed pretty intuitive, and not too hard to learn.

+1
source

Trying to create ulimate, the best, perfect DAL seems a little crazy - there are so many different application scenarios with different and competing requirements and needs that I don’t believe that anyone can come up with THE ONE final DAL.

You need to check some of the existing ORM tools, find out one or two of them, find out their strengths and, possibly, weaknesses, and then be able to choose the best one for each specific situation. I doubt it will always be the same .....

SubSonic is great for small, nimbler projects - like Linq-to-SQL if you use SQL Server as your backend. If you need more business opportunities, you should look at NHibernate, the ADO.NET Entity Framework, or other larger, more capable players (which are too complex and poorly suited for a small simple scenario).

I don’t think that THE THE ideal way to create DAL is there - find out what is available, find out how to choose the one that best suits your current needs, and do not reinvent yourself - use what is available there!

Mark

+1
source
+1
source

Linq to SQL is the best solution, or you can try the easiest solution http://fluentado.codeplex.com/

+1
source

Source: https://habr.com/ru/post/1286170/


All Articles