Where is the line between DAL and ORM?

chaos picture chaos · Feb 24, 2009 · Viewed 9.8k times · Source

The terms are often thrown around interchangeably, and there's clearly considerable overlap, but just as often it seems implied that people see something strongly implied by saying that a system is an ORM that isn't implied by it being a DAL. What is that? What, if any, are the key points that differentiate these types of system?

For example, let's say I have some code that implements Database, Table, Column and Row classes, populating them by automatic analysis of an existing database, allowing simplified interaction and so on. It understands, enforces, and takes advantage of structural relationships between database entities, such as foreign keys. All the entity models can be subclassed to load table-specific functionality onto them.

To what extent is this a DAL? To what extent is it an ORM? Why?

Answer

Steven A. Lowe picture Steven A. Lowe · Feb 24, 2009

ORM = Object-Relational Mapping

In an ORM, classes/objects in the application are mapped to database tables and operations for persistence, sometimes automagically.

DAL = Data-Access Layer

In a DAL, database operations are hidden behind a code facade.

An ORM is a kind of DAL, but not all DALs are ORMs.