Let us understand the ORM with a help of a figure given
below.
As we can see from the figure above that there is a new
layer that gets introduced called ORM. This layer acts as a bridge between DAL
and database. It generates SQL queries maps the Objects to the Tables.
ORM – Object Relational Mapper is a package that maps the objects
to the relational tables and Tables columns to the object attribute one to one.
Example: We have an Employee Table with some columns in it.
The figure below shows a business object of type Employee. It is not
mandatory to have the employee declaration as shown below.
The Code written below is in C#. It typically explains a
skeleton of business object.
Listing 1
Class Employee
{
public ID;
public Employee Name;
public Employee Salary;
}
The Employee class created needs to have a metadata that
helps the ORM map to the table. There are many ORM packages available that deal
with encapsulating the metadata with the class. We will look at the same in
the next section.
Figure 2