Monday, January 3, 2011

Nhibernate Quick Overview

Download all required nhibernate from following url.

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())

No comments:

ETG Consultancy

Web Designing Development Analysis & Promotion
Asp.Net 2.0 SQL WWF WCF SEO Marketing Ajax JQuery NHibernate MVC