主调代码:
using System;
using NHibernate;
using NHibernate.Cfg;
//using NHibernate.Demo.QuickStart; 
using NHibernate.Collection;
using NHibernate.Dialect;
using NHibernate.Tool.hbm2ddl; 
namespace  NHibernate.Demo.QuickStart
{
/// <summary>
/// Class1 の概要の説明です。
/// </summary>
class Class1
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Demo.QuickStart");
//cfg.AddXmlFile("User.hbm.xml"); ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction(); User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "[email protected]";
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(); session = factory.OpenSession(); User joeCool = (User)session.Load(typeof(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();// IList userList = session.CreateCriteria(typeof(User)).List();
// foreach(User user in userList)
// {
// System.Diagnostics.Debug.WriteLine(user.Id + " last logged in at " + user.LastLogon);
// }
//
// IList recentUsers = session.CreateCriteria(typeof(User))
// .Add(Expression.Expression.Gt("LastLogon", new DateTime(2004, 03, 14, 20, 0, 0)))
// .List();
//
// foreach(User user in recentUsers)
// {
// System.Diagnostics.Debug.WriteLine(user.Id + " last logged in at " + user.LastLogon);
// }
// tell NHibernate to close this Session
session.Close();
}
}
}

解决方案 »

  1.   

    影射类:
    using System;namespace NHibernate.Demo.QuickStart
    {
    public class User
    {
    private string id;
    private string userName;
    private string password;
    private string emailAddress;
    private DateTime lastLogon;
    public User()
    {
    }
    public string Id 
    {
    get { return id; }
    set { id = value; }
    } public string UserName 
    {
    get { return userName; }
    set { userName = value; }
    }
    public string Password 
    {
    get { return password; }
    set { password = value; }
    }
    public string EmailAddress 
    {
    get { return emailAddress; }
    set { emailAddress = value; }
    }
    public DateTime LastLogon 
    {
    get { return lastLogon; }
    set { lastLogon = value; }
    }

    }
    }
      

  2.   

    呵呵。那恭喜一下。我也正在研究NHibernate.大家多多交流
      

  3.   

    楼主有意思,自己提问,自己解决,Mark一下NHibernate
      

  4.   

    http://blog.csdn.net/billy_zh/
    有我学习nhibernate的一些文章。
      

  5.   

    我自己解决的,给些分激励一下!来的兄弟一人5分,billy_zh(牛仔) 的blog不错,给20!
      

  6.   

    sorry,我给不了分!请原谅!
      

  7.   

    NHibernate 的确是个好东东.但不知楼上的几位研究的如何.
    在此借楼主宝地一用问一个关于NHibernate 的问题.
    在使用NHibernate 的时候得到数据库记录集时不再是datatable而是对象集IList.
    请问将对象集IList绑定到datagrid时如何设定datagrid的列名?