111,125
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections;
using OKEC.Sample.NHibernate.NHibernateTest;
namespace OKEC.Sample.Spring
{
/// <summary>
/// StartMain 的摘要说明。
/// </summary>
public class StartMain
{
public StartMain()
{ //
// TODO: 在此处添加构造函数逻辑
//
}
[STAThread]
static void Main()
{
//Startup Spring & NHibernate Content
SpringContext.init();
//Test Spring IOC
HelloTest test = (HelloTest)SpringContext.Context.GetObject("Hello");
test.Test();
//Test Spring & NHibernate
UserDao dao = SpringContext.Context.GetObject("UserDao") as UserDao;
User newUser = null;
try
{
newUser = dao.Load("joe_cool");
}
catch
{}
if(newUser==null)
{
newUser = new 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
dao.SaveObject(newUser);
}
User joeCool = dao.Load("joe_cool");
// set Joe Cool's Last Login property
joeCool.LastLogon = DateTime.Now;
// flush the changes from the Session to the Database
dao.UpdateObject(joeCool);
IList recentUsers = dao.GetAllObjectsList();
foreach(User user in recentUsers)
{
//Assert.IsTrue(user.LastLogon > (new DateTime(2004, 03, 14, 20, 0, 0)) );
Console.WriteLine(user.UserName);
Console.WriteLine(user.Password);
}
Console.ReadLine();//让程序停留,回车关闭。
}
}
}