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


C# ISession.Close方法代码示例

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


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

示例1: Execute

        public void Execute(ISession session, long taskId, DateTime sentDate)
        {
            bool closeSession = false;
            if (session == null)
            {
                session = _businessSafeSessionManager.Session;
                closeSession = true;
            }

            var systemUser = session.Load<UserForAuditing>(SystemUser.Id);

            var taskDueTomorrowEscalation = new EscalationTaskDueTomorrow()
            {
                TaskId = taskId,
                TaskDueTomorrowEmailSentDate = sentDate,
                CreatedBy = systemUser,
                CreatedOn = DateTime.Now
            };
            session.Save(taskDueTomorrowEscalation);

            //Log4NetHelper.Log.Debug("Saved EscalationTaskDueTomorrow sent indicator");

            if (closeSession)
            {
                session.Close();
            }
        }
开发者ID:mnasif786,项目名称:Business-Safe,代码行数:27,代码来源:TaskDueTomorrowEmailSentCommand.cs

示例2: Execute

        public void Execute(ISession session, long accidentRecordId, DateTime sentDate)
        {
            bool closeSession = false;
            if (session == null)
            {
                session = _businessSafeSessionManager.Session;
                closeSession = true;
            }

            var systemUser = session.Load<UserForAuditing>(SystemUser.Id);

            var offWorkReminderEscalation = new EscalationOffWorkReminder()
            {
                AccidentRecordId = accidentRecordId,
                CreatedBy = systemUser,
                CreatedOn = DateTime.Now,
                OffWorkReminderEmailSentDate = DateTime.Now                
            };

            session.Save(offWorkReminderEscalation);

            //Log4NetHelper.Log.Debug("Saved EscalationOffWorkReminder sent indicator");

            if (closeSession)
            {
                session.Close();
            }               
        }
开发者ID:mnasif786,项目名称:Business-Safe,代码行数:28,代码来源:OffWorkReminderEmailSentCommand.cs

示例3: FinalizeSession

        private static void FinalizeSession(ISession session)
        {
            if (session == null || !session.IsOpen)
                return;

            try
            {
                if (session.Transaction != null && session.Transaction.IsActive)
                {
                    session.Flush();
                    session.Transaction.Commit();
                }
            }
            catch (Exception)
            {
                if (session.Transaction != null)
                    session.Transaction.Rollback();

                throw;
            }
            finally
            {
                session.Close();
                session.Dispose();
            }
        }
开发者ID:armw4,项目名称:dubb-load,代码行数:26,代码来源:SessionFactory.cs

示例4: QueryUsingReadonlyProperty

		public void QueryUsingReadonlyProperty()
		{
			using (session = OpenSession())
			{
				Nums nums1 = new Nums {ID = 1, NumA = 1, NumB = 2};
				session.Save(nums1);

				Nums nums2 = new Nums {ID = 2, NumA = 2, NumB = 2 };
				session.Save(nums2);

				Nums nums3 = new Nums {ID = 3, NumA = 5, NumB = 2 };
				session.Save(nums3);

				session.Flush();
				session.Clear();

				var nums = session.CreateQuery("from Nums b where b.Sum > 4").List<Nums>();

				Assert.That(nums.Count, Is.EqualTo(1));
				Assert.That(nums[0].Sum, Is.EqualTo(7));

				session.Delete("from Nums");
				session.Flush();
				session.Close();
			}
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:26,代码来源:Fixture.cs

示例5: Init

        public void Init() {
            _session = _sessionFactory.OpenSession();
            foreach (var killType in new[] { typeof(ContentTypeDefinitionRecord), typeof(ContentPartDefinitionRecord), typeof(ContentFieldDefinitionRecord) }) {
                foreach (var killRecord in _session.CreateCriteria(killType).List()) {
                    _session.Delete(killRecord);
                }
            }
            _session.Flush();
            _session.Close();
            _session.Dispose();
            _session = _sessionFactory.OpenSession();

            var builder = new ContainerBuilder();
            builder.RegisterAutoMocking();
            builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            builder.RegisterType(typeof(SettingsFormatter)).As(typeof(ISettingsFormatter));
            builder.RegisterType<Signals>().As<ISignals>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();

            _session = _sessionFactory.OpenSession();
            builder.RegisterInstance(_transactionManager = new TestTransactionManager(_session)).As<ITransactionManager>();

            _container = builder.Build();

        }
开发者ID:Golone,项目名称:Orchard,代码行数:27,代码来源:ContentDefinitionManagerTests.cs

示例6: SelectWithWhereClause

		public void SelectWithWhereClause()
		{
			using (session = OpenSession())
			{
				User user1 = new User();
				user1.UserName = "User1";
				session.Save(user1);

				User user2 = new User();
				user2.UserName = "User2";
				session.Save(user2);

				BlogPost post = new BlogPost();
				post.Title = "Post 1";
				post.Poster = user1;
				session.Save(post);

				session.Flush();
				session.Clear();

				User poster = (User) session.Get(typeof (User), user1.ID);

				string hql = "from BlogPost b where b.Poster = :poster";
				IList list = session.CreateQuery(hql).SetParameter("poster", poster).List();
				Assert.AreEqual(1, list.Count);
				BlogPost retrievedPost = (BlogPost) list[0];
				Assert.AreEqual(post.ID, retrievedPost.ID);
				Assert.AreEqual(user1.ID, retrievedPost.Poster.ID);

				session.Delete("from BlogPost");
				session.Delete("from User");
				session.Flush();
				session.Close();
			}
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:35,代码来源:Fixture.cs

示例7: 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

示例8: closeSession

 public void closeSession(ISession session)
 {
     if (session != null)
     {
         session.Close();
     }
 }
开发者ID:bruce5794163,项目名称:SmsSender,代码行数:7,代码来源:MQPool.cs

示例9: EndSession

        private static void EndSession(ISession session, bool commitTransaction = true)
        {
            try {
                if (session.Transaction != null && session.Transaction.IsActive) {
                    if (commitTransaction) {
                        try {
                            session.Transaction.Commit();
                        }
                        catch {
                            session.Transaction.Rollback();
                            throw;
                        }
                    }
                    else {
                        session.Transaction.Rollback();
                    }
                }
            }
            finally {
                if (session.IsOpen)
                    session.Close();

                session.Dispose();
            }
        }
开发者ID:jmptrader,项目名称:WebFrameworkMVC,代码行数:25,代码来源:SessionPerRequestModule.cs

示例10: CloseSession

        public void CloseSession(ISession currentSession)
        {
            try
            {
                if (currentSession != null)
                {
                    if (currentSession.IsOpen)
                    {
                        currentSession.Close();
                    }
                }

                currentSession = null;
            }
            catch (Exception)
            {
                if (currentSession != null)
                {
                    if (currentSession.IsOpen && currentSession.Transaction.IsActive)
                    {
                        currentSession.Transaction.Rollback();
                    }
                }

                throw;
            }
        }
开发者ID:GersonDias,项目名称:studies,代码行数:27,代码来源:SessionManagerInstance.cs

示例11: SetUpEachTest

        public void SetUpEachTest()
        {
            new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Execute(false, true, false, false);

            parent = new CompositeIdParent();

            child1 = new CompositeIdChild();
            child1.Parent = parent;
            child1.CompositeIdPart1 = "child1key1";
            child1.CompositeIdPart2 = "child1key2";

            child2 = new CompositeIdChild();
            child1.Parent = parent;
            child2.CompositeIdPart1 = "child2key1";
            child2.CompositeIdPart2 = "child2key2";

            session = sf.OpenSession();
            ITransaction tx = session.BeginTransaction();

            session.Save(parent);
            session.Save(child1);
            session.Save(child2);

            tx.Commit();
            session.Close();
        }
开发者ID:brumschlag,项目名称:rhino-tools,代码行数:26,代码来源:TestCompositeIds.cs

示例12: ReturnResponse

        internal HttpResponseMessage ReturnResponse(ISession session, HttpStatusCode code, double balance=-1)
        {
            if (session != null)
                session.Close();

            if (balance >= 0)
                return Request.CreateResponse(code, balance);
            else
                return Request.CreateResponse(code);
        }
开发者ID:xitz0r,项目名称:PaymentProcessorC-,代码行数:10,代码来源:StudentController.cs

示例13: OnActionExecuted

 public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
 {
     var transaction = _session.Transaction;
     if (transaction != null && transaction.IsActive)
     {
         transaction.Commit();
     }
     _session = CurrentSessionContext.Unbind(
         ObjectFactory.GetInstance<ISessionFactory>());
     _session.Close();
 }
开发者ID:RyanVice,项目名称:AuctionBlock,代码行数:11,代码来源:NHibernateTransactionAttribute.cs

示例14: getTransactions

 public IList getTransactions()
 {
     try
     {
         HibHelper.configSession();
         session = HibHelper.getOpenSession();
         transList = session.CreateCriteria(typeof(Transactions)).List();
         System.Diagnostics.Debug.WriteLine("Found list size :"+transList.Count.ToString());
         session.Close();
     }
     catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error in getTransactions : "+ e.Message); }
     return transList;
 }
开发者ID:Fabii23,项目名称:dotnetrepo,代码行数:13,代码来源:TransactionController.cs

示例15: ShouldSelectIdColumnsWithExists

        public void ShouldSelectIdColumnsWithExists()
        {
            session = sf.OpenSession();

            DetachedCriteria where =
                Where.CompositeIdParent.Children.Exists(Where.CompositeIdChild.CompositeIdPart1.Like("child"));

            IList<CompositeIdParent> applications =
                where.GetExecutableCriteria(session).SetResultTransformer(new DistinctRootEntityResultTransformer()).
                    List<CompositeIdParent>();

            session.Close();
        }
开发者ID:brumschlag,项目名称:rhino-tools,代码行数:13,代码来源:TestCompositeIds.cs


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