Facebook Twitter Gplus LinkedIn YouTube Google Maps RSS
Home Technical NHibernate Program.cs
formats

NHibernate Program.cs

Published on March 1, 2010 by in Technical

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

}
}
}

 
Tags:
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

12,873 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© All rights reserved to Cyberbrutus. 2012
credit

Switch to our mobile site