Exemplo n.º 1
0
        /// <summary>
        /// Creates the current UoW. The method will only
        /// create a new UoW if one is not already active. 
        /// Otherwise the existing UoW is returned
        /// </summary>
        /// <returns>The current IUnitOfWork</returns>
        public static IUnitOfWork CreateUnitOfWork()
        {
            UnitOfWork uow = GetCurrentUnitOfWork() as UnitOfWork;

            if (null == uow || !uow.IsActive)
            {
                uow = new UnitOfWork(m_sessionFactory.OpenSession());
                uow.Begin();
                Storage.SetCurrentUnitOfWork(uow);
            }

            return uow;
        }
Exemplo n.º 2
0
        public void Setup()
        {
            FluentConfiguration configuration = Fluently.Configure()
                .Database(SQLiteConfiguration.Standard
                    .InMemory()
                    .ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu")
                    .ShowSql());

            PersistenceModel pm = new PersistenceModel();
            pm.AddMappingsFromAssembly(typeof(Artist).Assembly);

            SingleConnectionSessionSourceForSQLiteInMemoryTesting ss = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(configuration.BuildConfiguration().Properties, pm);
            ss.BuildSchema();

            Session = ss.CreateSession();
            m_uow = new UnitOfWork(Session);

            SetupContext(Session);
            m_uow.Commit();

            Session.Clear();
        }