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


C# ISession.Clear方法代码示例

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


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

示例1: SetupContext

 public void SetupContext()
 {
     _session = _sessionFactory.OpenSession();
     new SchemaExport(_configuration).Execute(false, true, false, false, _session.Connection, null);
     CreateInitialData(_session);
     _session.Clear();
 }
开发者ID:tasluk,项目名称:hibernatingrhinos,代码行数:7,代码来源:Fixture_Base.cs

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

示例3: Init

        public void Init() {
            var builder = new ContainerBuilder();
            // builder.RegisterModule(new ImplicitCollectionSupportModule());
            builder.RegisterModule(new ContentModule());
            builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
            builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();

            builder.RegisterType<AlphaHandler>().As<IContentHandler>();
            builder.RegisterType<BetaHandler>().As<IContentHandler>();
            builder.RegisterType<GammaHandler>().As<IContentHandler>();
            builder.RegisterType<DeltaHandler>().As<IContentHandler>();
            builder.RegisterType<EpsilonHandler>().As<IContentHandler>();
            builder.RegisterType<FlavoredHandler>().As<IContentHandler>();
            builder.RegisterType<StyledHandler>().As<IContentHandler>();

            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));

            _session = _sessionFactory.OpenSession();
            builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();

            _session.Delete(string.Format("from {0}", typeof(GammaRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(DeltaRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(EpsilonRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(ContentItemVersionRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(ContentItemRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(ContentTypeRecord).FullName));
            _session.Flush();
            _session.Clear();

            _container = builder.Build();
            _manager = _container.Resolve<IContentManager>();

        }
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:33,代码来源:ContentQueryTests.cs

示例4: OnSetUp

		protected override void OnSetUp()
		{
			session = OpenSession();
			tran = session.BeginTransaction();

			// save some data
			Document doc = new Document(1, "test doc");
			Image img = new Image(1, doc, "c:\a.jpg");
			Paragraph para = new Paragraph(2, doc, "Arial");
			Page p1 = new Page(1, doc);
			p1.IsActive = true;
			Page p2 = new Page(2, doc);
			p2.IsActive = false;
			Review r = new Review(10, doc, "this is a good document"); // this id is 10 on purpose (to be != docId)

			session.Save(doc);
			session.Save(img);
			session.Save(para);
			session.Save(p1);
			session.Save(p2);
			session.Save(r);

			session.Flush();
			session.Clear();
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:25,代码来源:Fixture.cs

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

示例6: Before_each_test

 protected virtual void Before_each_test()
 {
     SessionSource = new SessionSource(new TestModel());
     Session = SessionSource.CreateSession();
     SessionSource.BuildSchema(Session);
     CreateInitialData(Session);
     Session.Clear();
 }
开发者ID:tasluk,项目名称:hibernatingrhinos,代码行数:8,代码来源:FixtureBase.cs

示例7: Context

 protected virtual void Context()
 {
     SessionSource = new SessionSource(new TestModel());
     Session = SessionSource.CreateSession();
     SessionSource.BuildSchema(Session);
     CreateInitialData(Session);
     Session.Flush();
     Session.Clear();
 }
开发者ID:tasluk,项目名称:hibernatingrhinos,代码行数:9,代码来源:FluentInterfaceFixtureBase.cs

示例8: DeleteMappings

 public void DeleteMappings(ISession session)
 {
     foreach (Type type in this.Mappings)
     {
         session.Delete("from " + type.FullName);
     }
     session.Flush();
     session.Clear();
 }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:9,代码来源:AbstractFixture.cs

示例9: OnSetUp

        protected override void OnSetUp()
        {
            base.OnSetUp();

            a = new Author();
            a.Name = "Voltaire";
            a2 = new Author();
            a2.Name = "Victor Hugo";
            a3 = new Author();
            a3.Name = "Moliere";
            a4 = new Author();
            a4.Name = "Proust";

            o = new Order();
            o.OrderNumber = "ACVBNM";

            o2 = new Order();
            o2.OrderNumber = "ZERTYD";

            p1 = new Product();
            p1.Name = "Candide";
            p1.Authors.Add(a);
            p1.Authors.Add(a2); //be creative

            p2 = new Product();
            p2.Name = "Le malade imaginaire";
            p2.Authors.Add(a3);
            p2.Orders.Add("Emmanuel", o);
            p2.Orders.Add("Gavin", o2);

            s = OpenSession();
            tx = s.BeginTransaction();
            s.Persist(a);
            s.Persist(a2);
            s.Persist(a3);
            s.Persist(a4);
            s.Persist(o);
            s.Persist(o2);
            s.Persist(p1);
            s.Persist(p2);
            tx.Commit();

            tx = s.BeginTransaction();

            s.Clear();
        }
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:46,代码来源:IndexedEmbeddedAndCollections.cs

示例10: Init

        public void Init() {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new ContentModule());
            builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
            builder.RegisterType<Signals>().As<ISignals>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
            builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
            builder.RegisterInstance(new Mock<IContentDisplay>().Object);
            builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataProvider = "SqlCe" });

            builder.RegisterType<AlphaPartHandler>().As<IContentHandler>();
            builder.RegisterType<BetaPartHandler>().As<IContentHandler>();
            builder.RegisterType<GammaPartHandler>().As<IContentHandler>();
            builder.RegisterType<DeltaPartHandler>().As<IContentHandler>();
            builder.RegisterType<EpsilonPartHandler>().As<IContentHandler>();
            builder.RegisterType<FlavoredPartHandler>().As<IContentHandler>();
            builder.RegisterType<StyledHandler>().As<IContentHandler>();
            builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
            builder.RegisterType<ShapeTableLocator>().As<IShapeTableLocator>();
            builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();

            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));

            builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
            builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
            builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();

            _session = _sessionFactory.OpenSession();
            builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();

            _session.Delete(string.Format("from {0}", typeof(GammaRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(DeltaRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(EpsilonRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(ContentItemVersionRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(ContentItemRecord).FullName));
            _session.Delete(string.Format("from {0}", typeof(ContentTypeRecord).FullName));
            _session.Flush();
            _session.Clear();

            _container = builder.Build();
            _manager = _container.Resolve<IContentManager>();

        }
开发者ID:anycall,项目名称:Orchard,代码行数:45,代码来源:ContentQueryTests.cs

示例11: TestSetUp

        public void TestSetUp()
        {
            _sqlLiteBuilder = new SqlLiteBuilder();
            _session = _sqlLiteBuilder.GetSession();

            InsertTestData();

            _session.Flush();

            _session.Clear();

            _joinConfiguration = new JoinConfiguration
            {
                ExpressionBuilder = new ExpressionBuilder(new TreeModelCriteriaTypeRegistry()),
                QueryableProvider = new NHibernateQueryableProvider(_session),
                JoinPathRegistry = new EmptyJoinPathRegistry()
            };
        }
开发者ID:chrisblock,项目名称:Criteria,代码行数:18,代码来源:SqlGenerationTests.cs

示例12: Setup

        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();
        }
开发者ID:triggerfish,项目名称:MvcTemplate,代码行数:22,代码来源:DatabaseTest.cs

示例13: SqlLiteTestDBAccess

        public SqlLiteTestDBAccess()
        {
            // configure NHibernate once for for all tests
            EnsureConfigured();

            // open one session for each test
            _session = _sessionFactory.OpenSession();

            // recreate the whole test database for each unit test
            RecreateDataBase();

            // replace default session creation logic to return the newly opened session meant to be used throughout the whole test;
            DataAccess.OpenSession = () =>
            {
                Console.WriteLine("----------------------------");
                Console.WriteLine("New session...");
                Console.WriteLine("----------------------------");

                _session.Clear();
                return new UndisposableSession(_session);
            };
        }
开发者ID:michal-franc,项目名称:learndash,代码行数:22,代码来源:SqlLiteTestDBAccess.cs

示例14: FailSession

 /// <summary>
 /// This is called when a session has a failure
 /// </summary>
 /// <param name="session">the session</param>
 public override void FailSession(ISession session)
 {
     hasSessionError = true;
     if (parentTransactionScope != null)
     {
         parentTransactionScope.VoteRollBack();
     }
     else
     {
         session.Clear();
     }
 }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:16,代码来源:DifferentDatabaseScope.cs

示例15: SaveRedundantSpectra

        private static void SaveRedundantSpectra(ISession sessionRedundant,
            IEnumerable<SpectrumKeyTime> redundantSpectraIds,
            IDictionary<string, long> dictFiles,
            DbRefSpectra refSpectra,
            Library library)
        {
            foreach (var specLiteKey in redundantSpectraIds)
            {
                if (specLiteKey.Key.RedundantId == 0)
                {
                    continue;
                }
                // If this source file has already been saved, get its database Id.
                // Otherwise, save it.
                long spectrumSourceId = GetSpecturmSourceId(sessionRedundant, specLiteKey.FilePath, dictFiles);

                // Get peaks for the redundant spectrum
                var peaksInfo = library.LoadSpectrum(specLiteKey.Key);
                var redundantSpectra = new DbRefSpectraRedundant
                                           {
                                               Id = specLiteKey.Key.RedundantId,
                                               PeptideSeq = refSpectra.PeptideSeq,
                                               PrecursorMZ = refSpectra.PrecursorMZ,
                                               PrecursorCharge = refSpectra.PrecursorCharge,
                                               PeptideModSeq = refSpectra.PeptideModSeq,
                                               NumPeaks = (ushort) peaksInfo.Peaks.Count(),
                                               Copies = refSpectra.Copies,
                                               RetentionTime = specLiteKey.Time.RetentionTime,
                                               IonMobilityValue = specLiteKey.Time.IonMobilityValue.GetValueOrDefault(),
                                               IonMobilityType = specLiteKey.Time.IonMobilityType.GetValueOrDefault(),
                                               IonMobilityHighEnergyDriftTimeOffsetMsec = specLiteKey.Time.IonMobilityHighEnergyDriftTimeOffsetMsec,
                                               FileId = spectrumSourceId
                                           };

                var peaks = new DbRefSpectraRedundantPeaks
                                {
                                    RefSpectra = redundantSpectra,
                                    PeakIntensity = IntensitiesToBytes(peaksInfo.Peaks),
                                    PeakMZ = MZsToBytes(peaksInfo.Peaks)
                                };
                redundantSpectra.Peaks = peaks;

                sessionRedundant.Save(redundantSpectra);
            }

            sessionRedundant.Flush();
            sessionRedundant.Clear();
        }
开发者ID:lgatto,项目名称:proteowizard,代码行数:48,代码来源:BlibDb.cs


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