这里是帮手;流利的nhibernate数据不存在
public class NHibernateHelper
{
private static ISessionFactory _sessionFactory;
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
InitSessionFactory();
return _sessionFactory;
}
}
private static void InitSessionFactory()
{
_sessionFactory =
Fluently.Configure().Database(
MsSqlConfiguration.MsSql2008.ConnectionString(
"ConnectionString").ShowSql).
Mappings(m => m.FluentMappings.AddFromAssemblyOf<Category>()).ExposeConfiguration(
cfg => new SchemaExport(cfg).Create(true, true)).BuildSessionFactory();
}
public static ISession OpenSession()
{
return SessionFactory.OpenSession();
}
}
下面的代码是代码存储数据:
using(var session = NHibernateHelper.OpenSession())
{
using (var tx = session.BeginTransaction())
{
session.Save(category);
tx.Commit();
}
}
我的问题是,当我运行这段代码和我刷新数据库,我看到数据正在经历。
当我重新启动应用程序时,数据消失了。
我该如何坚持数据到数据库?
导出架构是否重新创建数据库或只是在需要时更新? – wiero 2012-03-27 08:06:45