Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ORM and DAL?

I have read up on both, but it has just confused me more. I have tried to find the differences (and similarities), but am unable to convince myself. Both of them are an intermediate layer between the business logic and the database. Is there a difference or are they the same?

like image 839
ASR4 Avatar asked Mar 26 '18 20:03

ASR4


People also ask

What is the difference between Dao and DAL?

DAL is an architectural term, DAOs are a design detail.

What is a DAL in programming?

A data access layer (DAL) in computer software is a layer of a computer program which provides simplified access to data stored in persistent storage of some kind, such as an entity-relational database. This acronym is prevalently used in Microsoft environments.

What ORM means?

Object-relational mapping (ORM) is a mechanism that makes it possible to address, access and manipulate objects without having to consider how those objects relate to their data sources.

What is ORM and non ORM?

Object-Relational Mapping (ORM) is a technique that lets you query and manipulate data from a database using an object-oriented paradigm. When talking about ORM, most people are referring to a library that implements the Object-Relational Mapping technique, hence the phrase "an ORM".


2 Answers

ORM (Object/Relational Mapper):

  • It is a library/tool that executes the input SQL query (some ORMs also generate the query for you) and converts (maps) output DataReader (or equivalent in other languages) to your strongly typed objects. This is basic feature of any ORM.
  • That said, it works as layer between your data storage and your application.
  • Core role of ORM is mapping; it always (mostly?) return strongly typed objects. In rare cases, it may return values in basic data types provided by language like int, string etc.
  • This is application agnostic; except that you have to configure this separately per application/data store.
  • This only deals with RDBMS.
  • Some advanced ORMs (full-ORM) can be used as DAL; this is mostly a design decision.
  • Being application agnostic, this cannot implement your specific persistence logic.

DAL (Data Access Layer):

  • It is a layer that handles all your data needs. But this is different from ORM.
  • Actually, this may use ORM internally for any RDBMS communication. Although DAL can be designed without using any ORM also.
  • DAL may return strongly typed objects but not always necessary.
  • DAL may communicate with any form of data store including Web API, XML, RDBMS.
  • Mapping may or may not be the part of DAL depending on how it is being designed.
  • This is application specific.
  • There are different patterns available to implement DAL as Data Access Object or Repository.
  • Being designed for specific application, this may include your specific persistence logic like data encryption.
like image 180
Amit Joshi Avatar answered Nov 25 '22 16:11

Amit Joshi


ORM is a general programming approach centered around dealing with data in systems in a way that presents them (and lets you work with them) as objects in your programming language of choice. Even if the data comes from a source that has nothing to do with your chosen programming language. The abstract concept of interacting with data through an object "veneer" is ORM.

DAL on the other hand is simply the name for the entire collection of things that a programming language offers that makes working with stored data easier. It's effectively a convenient term for talking about "all the APIs for dealing with stored data".

And to tie it together: "The Data Access Layer for your chosen programming language may use Object-Relational mapping."

like image 36
Mike 'Pomax' Kamermans Avatar answered Nov 25 '22 17:11

Mike 'Pomax' Kamermans