NHibernate 空气是哪么的清新,世界是多么的美好
哪个该死的问题 解决后,接下一来事情 竟然是如此顺利
我写了个文件,测试 插入 更新 删除 都是一次性通过,
using System;
using System.Collections;
using NHibernate;
using NHibernate.Cfg;
using NUnit.Framework;
namespace pb.testdal.Db
{
/// <summary>
/// testusers 的摘要说明。
/// </summary>
///
[TestFixture]
public class testusers
{
public testusers()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
[Test]public void add()
{
Configuration cfg=new Configuration();
cfg.AddAssembly("testdal1");
cfg.AddXmlFile("users.hbm.xml");
ISessionFactory factory=cfg.BuildSessionFactory();
ISession session=factory.OpenSession();
ITransaction transaction=session.BeginTransaction();
users newUser=new users();
newUser.ID="pingbo1";
newUser.Name="joseph Cool";
newUser.Password="abc123";
newUser.EmailAddress="joe@cool.com";
newUser.LastLogon=DateTime.Now;
session.Save(newUser);
transaction.Commit();
session.Close();
}
[Test]public void update()
{
Configuration cfg=new Configuration();
cfg.AddAssembly("testdal1");
cfg.AddXmlFile("users.hbm.xml");
ISessionFactory factory=cfg.BuildSessionFactory();
ISession session=factory.OpenSession();
ITransaction transaction=session.BeginTransaction();
users newUser=new users();
newUser.ID="pingbo";
newUser.Name="zykj2000";
newUser.Password="24976904";
newUser.EmailAddress="zykj_2000@163.com";
newUser.LastLogon=DateTime.Now;
session.Update(newUser,"pingbo");
transaction.Commit();
session.Close();
}
[Test]public void del()
{
Configuration cfg=new Configuration();
cfg.AddAssembly("testdal1");
cfg.AddXmlFile("users.hbm.xml");
ISessionFactory factory=cfg.BuildSessionFactory();
ISession session=factory.OpenSession();
ITransaction transaction=session.BeginTransaction();
users newUser=new users();
newUser.ID="pingbo1";
session.Delete(newUser);
transaction.Commit();
session.Close();
}
}
}
using System.Collections;
using NHibernate;
using NHibernate.Cfg;
using NUnit.Framework;
namespace pb.testdal.Db
{
/// <summary>
/// testusers 的摘要说明。
/// </summary>
///
[TestFixture]
public class testusers
{
public testusers()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
[Test]public void add()
{
Configuration cfg=new Configuration();
cfg.AddAssembly("testdal1");
cfg.AddXmlFile("users.hbm.xml");
ISessionFactory factory=cfg.BuildSessionFactory();
ISession session=factory.OpenSession();
ITransaction transaction=session.BeginTransaction();
users newUser=new users();
newUser.ID="pingbo1";
newUser.Name="joseph Cool";
newUser.Password="abc123";
newUser.EmailAddress="joe@cool.com";
newUser.LastLogon=DateTime.Now;
session.Save(newUser);
transaction.Commit();
session.Close();
}
[Test]public void update()
{
Configuration cfg=new Configuration();
cfg.AddAssembly("testdal1");
cfg.AddXmlFile("users.hbm.xml");
ISessionFactory factory=cfg.BuildSessionFactory();
ISession session=factory.OpenSession();
ITransaction transaction=session.BeginTransaction();
users newUser=new users();
newUser.ID="pingbo";
newUser.Name="zykj2000";
newUser.Password="24976904";
newUser.EmailAddress="zykj_2000@163.com";
newUser.LastLogon=DateTime.Now;
session.Update(newUser,"pingbo");
transaction.Commit();
session.Close();
}
[Test]public void del()
{
Configuration cfg=new Configuration();
cfg.AddAssembly("testdal1");
cfg.AddXmlFile("users.hbm.xml");
ISessionFactory factory=cfg.BuildSessionFactory();
ISession session=factory.OpenSession();
ITransaction transaction=session.BeginTransaction();
users newUser=new users();
newUser.ID="pingbo1";
session.Delete(newUser);
transaction.Commit();
session.Close();
}
}
}
从最基本的入手,全部通过了,接着努力