這裏是幫手;流利的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