using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using Castle.Core;
using Castle.DynamicProxy;
using NHibernate.Bytecode;
namespace HiberDriver
{
class Program
{
static void Main(string[] args)
{
Configuration cfg = new Configuration();
cfg.AddAssembly(“HiberClass”);
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
HiberClass.User newUser = new HiberClass.User();
newUser.Id = “joe_cool”;
newUser.UserName = “Joseph Cool”;
newUser.Password = “abc123″;
newUser.EmailAddress = “joe@cool.com”;
newUser.LastLogon = DateTime.Now;
// Tell NHibernate that this object should be saved
session.Save(newUser);
// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
// open another session to retrieve the just inserted user
session = factory.OpenSession();
HiberClass.User joeCool = (HiberClass.User)session.Load(typeof(HiberClass.User), “joe_cool”);
// set Joe Cool’s Last Login property
joeCool.LastLogon = DateTime.Now;
// flush the changes from the Session to the Database
session.Flush();
}
}
}






