【发布时间】:2011-09-18 21:32:38
【问题描述】:
在尝试加载页面 (mvc 3) 时,我没有收到“没有会话绑定到当前上下文”错误。
public static ISessionFactory BuildSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008 //
.ConnectionString(@"Server=.\SQLExpress;Database=db1;Uid=dev;Pwd=123;")
.ShowSql())
//.ExposeConfiguration(c => c.SetProperty("current_session_context_class", "web"))
//.CurrentSessionContext<CallSessionContext>()
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<User>())
.ExposeConfiguration(cfg => new SchemaExport(cfg)
.Create(false, false))
.BuildSessionFactory();
}
实际错误在我的 Repository.cs 文件中:
第 114 行:公共虚拟 T Get(int id) 第 115 行:{ 第 116 行:返回 _sessionFactory.GetCurrentSession().Get(id); 第 117 行:} 第 118 行:
当我调试它时,_sessionFactory 不是 null 或任何东西,它似乎无法找到绑定的会话。
我在 web.config 中连接了 httpmodule,它确实可以运行,所以这不是问题。
在我的休眠配置中,我都尝试了:
.ExposeConfiguration(c => c.SetProperty("current_session_context_class", "web"))
和
.CurrentSessionContext<CallSessionContext>()
但这没有用。
【问题讨论】:
-
当您说“在我的 nhibernate 配置中,我都尝试了:”时,您给出的示例都是相同的。您能否编辑您的问题以提供您尝试过的其他配置! ^^
-
还尝试在
CurrentSession()和Bind(方法中设置断点,以确保它们被调用。
标签: c# asp.net-mvc nhibernate fluent-nhibernate