本文整理汇总了C#中ISessionFactory.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionFactory.Dispose方法的具体用法?C# ISessionFactory.Dispose怎么用?C# ISessionFactory.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISessionFactory
的用法示例。
在下文中一共展示了ISessionFactory.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
private void Run()
{
var shardedConfiguration = BuildShardedConfiguration();
CreateSchema(shardedConfiguration);
sessionFactory = shardedConfiguration.BuildShardedSessionFactory();
AddData();
ISession session = sessionFactory.OpenSession();
try
{
ICriteria crit = session.CreateCriteria(typeof(WeatherReport), "weather");
var count = crit.List();
if (count != null) Console.WriteLine(count.Count);
crit.Add(Restrictions.Gt("Temperature", 33));
var reports = crit.List();
if (reports != null) Console.WriteLine(reports.Count);
}
finally
{
session.Close();
}
sessionFactory.Dispose();
Console.WriteLine("Done.");
Console.ReadKey(true);
}
示例2: SaveOrUpdateEntity
/// <summary>
/// 保存或更新实体
/// </summary>
/// <param name="entity"></param>
public void SaveOrUpdateEntity(BaseEntity entity)
{
ISessionFactory factory = null;
ISession session = null;
ITransaction transaction = null;
// Tell NHibernate that this object should be updated
try
{
factory = Connection.getConfiguration().BuildSessionFactory();
session = factory.OpenSession();
transaction = session.BeginTransaction();
session.SaveOrUpdate(session.Merge(entity));
// commit all of the changes to the DB and close the ISession
transaction.Commit();
//MessageBox.Show("保存成功");
}
catch (Exception e)
{
if (transaction != null && transaction.IsActive)
{
transaction.Rollback();
}
throw e;
}
finally
{
if (session != null && session.IsOpen)
{
factory.Close();
session.Clear();
session.Close();
factory.Dispose();
session.Dispose();
}
}
}
示例3: getSessionFactory
private static ISessionFactory getSessionFactory(ref ISessionFactory factory, NHibernate.Cfg.Configuration cfg)
{
if (factory != null)
{
if (factory.IsClosed)
{
factory.Dispose();
factory = null;
}
}
if (factory == null)
{
factory = cfg.BuildSessionFactory();
}
return factory;
}