当前位置: 首页>>代码示例>>C#>>正文


C# ISession.BeginTransaction方法代码示例

本文整理汇总了C#中ISession.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.BeginTransaction方法的具体用法?C# ISession.BeginTransaction怎么用?C# ISession.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISession的用法示例。


在下文中一共展示了ISession.BeginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetModificationDateIntegrationTests

        public SetModificationDateIntegrationTests()
        {
            listener =	new SetModificationTimeFlushEntityEventListener()
                {
                    CurrentDateTimeProvider = () => defaultDate
                };

            Configuration config = null;
            sessionFactory = Fluently.Configure()
                .Database(SQLiteConfiguration.Standard.InMemory)
                .Mappings(m =>
                {
                    m.FluentMappings.Add<ThingMap>();
                    m.FluentMappings.Add<InheritedThingMap>();
                    m.FluentMappings.Add<RelatedThingMap>();
                })
                .ExposeConfiguration(cfg =>
                {
                    listener.Register(cfg);
                    config = cfg;
                })
                .BuildSessionFactory();

            session = sessionFactory.OpenSession();

            using (var tx = session.BeginTransaction())
            {
                new SchemaExport(config).Execute(false, true, false, session.Connection, null);
                tx.Commit();
            }

            session.BeginTransaction();
        }
开发者ID:jfromaniello,项目名称:NHListenerTests,代码行数:33,代码来源:SetModificationDateListenerTests.cs

示例2: NHibernateTransaction

    public NHibernateTransaction(ISession session, IsolationLevel? isolation = null)
    {
      Assertion.NotNull(session);

      this.session = session;
      this.transaction = isolation != null ? session.BeginTransaction(isolation.Value) : session.BeginTransaction();
      this.isolation = isolation ?? IsolationLevel.Unspecified;
    }
开发者ID:prokhor-ozornin,项目名称:Catharsis.NET.Repository,代码行数:8,代码来源:NHibernateTransaction.cs

示例3: SessionUnitOfWork

        public SessionUnitOfWork(ISession session, ILog log)
        {
            if (session == null)
            {
                throw Error.ArgumentNull("session");
            }

            if (log == null)
            {
                throw Error.ArgumentNull("log");
            }

            Session = session;
            Log = log;

            if (!Session.Transaction.IsActive)
            {
                Session.BeginTransaction();
                IsInteract = true;
            }
            else
            {
                IsInteract = false;
            }
        }
开发者ID:pleb,项目名称:Chillow,代码行数:25,代码来源:SessionUnitOfWork.cs

示例4: Run

        public void Run()
        {
            rng = new Random(376473672);
            var sessionFactory = CreateSessionFactory();
            // create properties
            var properties = new NameValueCollection();
            properties["level"] = "All";
            using (session = sessionFactory.OpenSession())
            {
                using (var trans = session.BeginTransaction())
                {
                    CreateProducts();
                    trans.Commit();
                }
            }

            var customerCount = 30;
            for (var i = 0; i < customerCount; i++)
            {
                using (session = sessionFactory.OpenSession())
                {
                    using (var trans = session.BeginTransaction())
                    {
                        CreateCustomerWithOrders();
                        trans.Commit();
                    }
                }
            }

            var pth = new TestPomonaHost(new Uri("http://localhost:4321/"), sessionFactory);
            pth.Start();

            Console.ReadLine();
            pth.Stop();
        }
开发者ID:BeeWarloc,项目名称:Pomona,代码行数:35,代码来源:Program.cs

示例5: UnitOfWork

        public UnitOfWork(ISession session)
        {
            Guard.AgainstNull(() => session);

            this.session = session;
            this.transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);
        }
开发者ID:hermanpotgieter,项目名称:Code.Pizza,代码行数:7,代码来源:UnitOfWork.cs

示例6: NHibernateBlogService

        public NHibernateBlogService(bool autoCommit)
        {
            AutoCommit = autoCommit;

            _session = SessionFactory.OpenSession();
            _transaction = _session.BeginTransaction();
        }
开发者ID:gmstr,项目名称:GMSBlog,代码行数:7,代码来源:NHibernateBlogService.cs

示例7: Setup

 public void Setup()
 {
     session = WindsorPersistenceFixture.Container.Resolve<ISession>();
     repository = new SecurityRepository();
     repository.Session = session;
     tx = session.BeginTransaction();
 }
开发者ID:PolishDev,项目名称:shop-manager,代码行数:7,代码来源:SecurityRepositoryTests.cs

示例8: SetUp

 public void SetUp()
 {
     // new session on every test
     Session = FixtureSetup.Container.Resolve<ISessionFactory>().OpenSession();
     FixtureSetup.Container.Register(x => this.Session);
     _transaction = Session.BeginTransaction();
 }
开发者ID:jpoehls,项目名称:Template,代码行数:7,代码来源:SessionTestsBase.cs

示例9: SetUp

 public void SetUp()
 {
     session = CreateSession();
     session.BeginTransaction();
     usrRep = new UserRepository(session);
     repositorySetUp();
 }
开发者ID:bagheera,项目名称:getin,代码行数:7,代码来源:UserPreferenceRepositoryTest.cs

示例10: RebuildDatabase

        public void RebuildDatabase()
        {
            ITransaction transaction = null;
            try
            {
                var factoryFactory = new NHibernateSessionFactory();
                ISessionFactory sessionFactory = factoryFactory.GetSessionFactory();
                string[] dropScripts = factoryFactory.Configuration.GenerateDropSchemaScript(((ISessionFactoryImplementor)sessionFactory).Dialect);
                string[] createScripts = factoryFactory.Configuration.GenerateSchemaCreationScript(((ISessionFactoryImplementor)sessionFactory).Dialect);

                session = sessionFactory.OpenSession();
                ExecuteScripts(dropScripts, session.Connection);
                ExecuteScripts(createScripts, session.Connection);
                SaveScripts(createScripts, "create.sql");

                transaction = session.BeginTransaction();
                var repository = new Repository(session);
                var data = new Data();
                data.Build(repository);
            }
            finally
            {
                if (session != null)
                {
                    if (transaction != null && transaction.IsActive)
                    {
                        transaction.Commit();
                    }
                    session.Close();
                    session.Dispose();
                }
            }
        }
开发者ID:liammclennan,项目名称:shortest-path,代码行数:33,代码来源:Db.cs

示例11: Populate

        private void Populate(ISession session)
        {
            Assert.IsNotNull(session);
            session.BeginTransaction();
            try
            {
                var person = new Person
                                 {
                                     FirstName = "brady",
                                     LastName = "gaster"
                                 };

                session.Save(person);
                Assert.Greater(person.Id, 0);

                int newPersonId = person.Id;

                person.FirstName = "Gina";
                session.Update(person);

                Assert.Greater(person.Id, 0);
                Assert.IsTrue(person.Id == newPersonId);
                session.Transaction.Commit();
            }
            catch
            {
                session.Transaction.Rollback();
            }
        }
开发者ID:beefarino,项目名称:NHibernate-QuickStart,代码行数:29,代码来源:SessionFactoryTests.cs

示例12: BuyNewComputers

        public bool BuyNewComputers(Computer[] cts)
        {
            bool bReturn = true;
            try
            {
                session = sessionFactory.OpenSession();
                tx = session.BeginTransaction();

                for(int i=0;i<cts.Length;i++)
                {
                    session.Save(cts[i]);
                }

                tx.Commit();
            }
            catch(Exception ex)
            {
                bReturn = false;
            }
            finally
            {
                session.Flush();
                session.Disconnect();
            }
            return bReturn;
        }
开发者ID:hungtrinh81,项目名称:leonworkshop,代码行数:26,代码来源:DataAccesser.cs

示例13: OnActionExecuting

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            DataSession = MvcApplication.SessionFactory.OpenSession();
            DataSession.BeginTransaction();

            base.OnActionExecuting(filterContext);
        }
开发者ID:Gilligan128,项目名称:Maelstrom,代码行数:7,代码来源:MaelstromController.cs

示例14: Transaction

 public static void Transaction(ISession session, IsolationLevel level, Action transactional)
 {
     // If we are already in a transaction, don't start a new one
     ITransaction tx = null;
     if (session.Transaction.IsActive)
     {
         tx = session.Transaction;
     }
     else
     {
         tx = session.BeginTransaction(level);
     }
     try
     {
         transactional();
         tx.Commit();
     }
     catch
     {
         tx.Rollback();
         throw;
     }
     finally
     {
         tx.Dispose();
     }
 }
开发者ID:ziyasal,项目名称:RepositoryT.NHibernate,代码行数:27,代码来源:CommitWith.Transaction.cs

示例15: TemporaryReadonlySession

 public TemporaryReadonlySession(ISessionFactory factory)
 {
     this.oldtemporary = AutomativeCurrentSessionContext.temporary;
     Session = AutomativeCurrentSessionContext.temporary = factory.OpenSession();
     Session.FlushMode = FlushMode.Never;
     Session.BeginTransaction();
 }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:7,代码来源:TemporaryReadonlySession.cs


注:本文中的ISession.BeginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。