主调代码:
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();
}
}
}
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();
}
}
}
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; }
}
}
}
有我学习nhibernate的一些文章。
在此借楼主宝地一用问一个关于NHibernate 的问题.
在使用NHibernate 的时候得到数据库记录集时不再是datatable而是对象集IList.
请问将对象集IList绑定到datagrid时如何设定datagrid的列名?