Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Diagnostics;
- using FluentNHibernate.Cfg;
- using FluentNHibernate.Cfg.Db;
- using NHibernate;
- using NHibernate.ByteCode.Castle;
- using NHibernate.Context;
- using Webdevelopment.Hif.Data.Maps;
- namespace WebApp.App_Code
- {
- public class NhibernateInit
- {
- public static ISessionFactory SessionFactory { get; private set; }
- // TODO: this should be moved in an easy way to configurate from outside
- public static void Setup()
- {
- InitProfiler();
- SessionFactory =
- Fluently.Configure().Database(MsSqlConfiguration.MsSql2008
- .ConnectionString(
- c => c.Server("192.168.1.7").Database("appexnet").Username("appexnet").Password("SQL4dev"))
- .ShowSql().FormatSql()
- .CurrentSessionContext("web")
- .ProxyFactoryFactory<ProxyFactoryFactory>())
- .Mappings(m => m.FluentMappings.AddFromAssemblyOf<AdvertiserCategoryClassMap>())
- .BuildSessionFactory();
- }
- public static void DetachSession()
- {
- var session = WebSessionContext.Unbind(SessionFactory);
- if (session != null)
- {
- if (session.Transaction != null && session.Transaction.IsActive)
- session.Transaction.Commit();
- session.Close();
- }
- }
- public static void AttachSession()
- {
- var session = SessionFactory.OpenSession();
- WebSessionContext.Bind(session);
- session.BeginTransaction();
- }
- [Conditional("DEBUG")]
- private static void InitProfiler()
- {
- HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
- }
- }
- }
Add Comment
Please, Sign In to add comment