Showing posts with label Nhibernate Quick Overview. Show all posts
Showing posts with label Nhibernate Quick Overview. Show all posts

Monday, January 3, 2011

Nhibernate Quick Overview

Download all required nhibernate from following url.

http://sourceforge.net/projects/nhibernate/


How to use ICriteria ?

ICriteria criteria = SessionManager.CurrentSession.CreateCriteria();
criteria = criteria.Add(NHibernate.Criterion.Expression.Eq("StudentId", 48));
Student stu= criteria.UniqueResult();

How to Map two or more database table from one object in nhibernate ?

Suppose thhe following school object does not have a property called Student ,

public class School
{
public virtual ISet Students { get; set; }
}


Now in hbm you can map like

< set name="Students" table="Students" schema="oneSchool" cascade="all-delete-orphan" lazy="true" where ="AdminDate() between StartDate And IsNull(EndDate,GetDate())">
< key column="SchooldId" / >
< many-to-many class="Student" column="StudentId"/ >
< /set>

how to use transaction in Nhibernate ?

use Nhibernate.Transaction namespace reference;
using (ITransaction tran = SessionManager.CurrentSession.BeginTransaction())
{
tran.commit();
}