Top 10 Must Have Features in O/R Mapping Tools

/* Note one-to-many self relationship thru "reports_to" */
CREATE TABLE t_employees (
employee_id int IDENTITY (1, 1) NOT NULL,
name nvarchar (40) NOT NULL,
birth_date datetime NULL,
photo image NULL,
reports_to int NULL,
)

// Domain object class for t_employees table
public class Employee
{
Int32			_employeeId;
String			_name;
DateTime		_birthDate;
Byte[]			_photo;
Int32			_reportsTo;
ArrayList		_subordinates;
Employee		_supervisor;

Int32 EmployeeId {
	get { return _employeeId;} set { _employeeId = value; }
}
String Name {
	get { return _name; } set { _name = value; }
}
DateTime BirthDate {
	get { return _birthDate; } set { _birthDate = value; }
}
Byte[] Photo {
	get { return _photo; } set { _photo = value; }
}
Int32 ReportsTo {
	get { return _reportsTo; } set { _reportsTo = value; }
}
ArrayList Subordinates {
	get { return _subordinates; } set { _subordinates = value; }
}
Employee Supervisor {
	get { return _employee; } set { _employee = value; }
}
}

// Persistence object for Employee class
public interface IEmployeeFactory
{
void Load(Employee object, int nDepth);
void Insert(Employee object);
void Update(Employee object);
void Delete(Employee object);

// Query methods
ArrayList FindSomeEmployees(); 

// Relationship methods
void LoadSupervisor (Employee emp);
void LoadSubordinates(Employee emp, int nDepth);
}

Below is an example of how a client application will use this code:

public class NorthwindApp
{
static void Main (string[] args) {
	Employee emp = new Employee();
	EmployeeFactory empFactory = new EmployeeFactory();

	// Let's load a employee from Northwind database.
	emp.EmployeeId = 10045;
	empFactory.load(emp);

	// empList is a collection of Employee objects
	ArrayList empList = empFactory.FindSomeEmployees();
	// subList is a collection of Employee's subordinates objects
	ArrayList subList = empFactory.LoadSubordinates(emp, 1);

	// supervisor is Employee's supervisor object
	Employee supervisor = empFactory.LoadSupervisor(emp);
}
}

Previous Page | Next Page
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

If you found this page useful, bookmark and share it on:

 
Embedded Star Newsletter
Don't have time to visit Embedded Star everyday? Then sign up for our free newsletter. We'll send you an email when we have something to share with you. Your email address will be kept confidential and we will not share, sell, or rent it to anyone. You can unsubscribe at any time by clicking a link in the email.

Enter your email address to sign up for our free newsletter:   

If you are familiar with RSS feeds, you can also sign up for our free blog feed. Our RSS feed is updated in real-time while our newsletter is updated daily.