/// <summary> /// 修改考试过程信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public static void UpdateExamProcess(ExamProcess model) { if (model != null) { var conf = new Configuration().Configure(); ISession session = NHibernateHelper.GetSession(); //配置NHibernate //在Configuration中添加HbmMapping conf.AddDeserializedMapping(NHibernateHelper.GetEntityMapping<ExamProcess>(), "ExamProcessXML"); //配置数据库架构元数据 SchemaMetadataUpdater.QuoteTableAndColumns(conf); //建立SessionFactory var factory = conf.BuildSessionFactory(); //打开Session做持久化数据 using (session = factory.OpenSession()) { using (var tx = session.BeginTransaction()) { var list=session.CreateQuery("from ExamProcess E where E.Id='"+model.Id.ToString()+"'") .List<ExamProcess>(); if (list.Count > 0) { if (model.EndTime > DateTime.Parse("2000/01/01") ) { list[0].EndTime = model.EndTime; } list[0].Evaluate = model.Evaluate; } session.Update(list[0]); tx.Commit(); } } } }
/// <summary> /// 保存考试过程信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public static int SaveExamProcess(ExamProcess model) { int id = -1; if (model != null) { var conf = new Configuration().Configure(); ISession session = NHibernateHelper.GetSession(); //配置NHibernate //在Configuration中添加HbmMapping conf.AddDeserializedMapping(NHibernateHelper.GetEntityMapping<ExamProcess>(), "ExamProcessXML"); //配置数据库架构元数据 SchemaMetadataUpdater.QuoteTableAndColumns(conf); //建立SessionFactory var factory = conf.BuildSessionFactory(); //打开Session做持久化数据 using (session = factory.OpenSession()) { using (var tx = session.BeginTransaction()) { id = (int)session.Save(model); tx.Commit(); } } } return id; }