NHibernate Integrated Queries Code Review
Define Person, Role and Salary Classes
Code Download
- Download Description:nhibernate integrated queries download
- .NET Framework:2.0
- .NET Language:C#
- Date Published:2009-07-01
- Download Size:2,926 KB
Code Review
- NHibernate Integrated Queries Code Review: Define Person, Role and Salary Classes
- NHibernate Integrated Queries Code Review: Mapping the Class and Database Objects Using XML Mapping File
- NHibernate Integrated Queries Code Review: Define NHibernate Application Configuration
- NHibernate Integrated Queries Code Review: Manipulate the Database using NHibernate
Code Walkthrough
Define the Person class which maps to the Person database table.
public Person() { }
public virtual Role Role { get { return this.m_role; } set { this.m_role = value; } } public virtual Int32 ID { get { return this.m_id; } set { this.m_id = value; } } public virtual Int32 IDRole { get { return this.m_idRole; } set { this.m_idRole = value; } } public virtual String LastName { get { return this.m_lastName; } set { this.m_lastName = value; } } public virtual String FirstName { get { return this.m_firstName; } set { this.m_firstName = value; } } public virtual IList<Salary> Salaries { get { return this.m_salary; } set { this.m_salary = value; } } }
The object relational mapping of the Person object to the Person database table is handled in the XML Mapping file.
The IList collection is used by NHibernate to store a collection of Salary objects. In the Person class, one Person object can be linked to many Salary objects. The Role object represents the role to which the person is associated to.
Define the Role class which maps to the Role database table.
public Role() { } public virtual Int32 ID { get { return this.m_id; } set { this.m_id = value; } } public virtual ISet People { get { return this.m_people; } set { this.m_people = value; } } public virtual String RoleDescription { get { return this.m_roleDescription; } set { this.m_roleDescription = value; } } }
The object relational mapping of the Role object to the Role database table is handled in the XML Mapping file.
The ISet class is a special collection used by NHibernate and implements the IEnumerable interface.
The ISet collection is used by NHibernate to store a collection of Person objects. In the Role class, one Role object can be associated with many Person objects.
Define the Salary class which maps to the Salary database table.
public virtual Int32 ID { get { return this.m_id; } set { this.m_id = value; } } public virtual Person Person { get { return this.m_person; } set { this.m_person = value; } } public virtual Int32 Year { get { return this.m_year; } set { this.m_year = value; } } public virtual Double SalaryYear { get { return this.m_salaryYear; } set { this.m_salaryYear = value; } } }
The object relational mapping of the Salary object to the Salary database table is handled in the XML Mapping file.
The Person object represents the person to which the salary is linked to.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!