,我發現了錯誤:在我NHibernate的測試項目沒有當前會話的上下文設置錯誤
No CurrentSessionContext configured (set the property current_session_context_class).
我不知道要放什麼東西,我有這樣的:
public class NhDbHelper
{
public NhDbHelper()
{
CreateSessionFactory();
}
private ISessionFactory _sessionFactory;
public ISessionFactory SessionFactory
{
get { return _sessionFactory; }
}
private void CreateSessionFactory()
{
_sessionFactory = Fluently
.Configure()
.Database((MsSqlConfiguration.MsSql2008 //
.ConnectionString(@"Server=.\SQLExpress;Database=abc;Uid=sa;Pwd=123;")
.ShowSql()))
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<UserMap>())
.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true))
.BuildSessionFactory();
}
}
然後在我的倉庫中,我只是在助手中使用SessionFactory屬性。
http://stackoverflow.com/questions/7454589/no-session-bound-to-the-current-context/7458905#7458905 –