Пример #1
0
        public async Task DefaultAsync()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.DomainModel.Simple.hbm.xml", typeof(Simple).Assembly);
            cfg.SetProperty(Environment.Hbm2ddlAuto, "create-drop");
            ISessionFactory sf = cfg.BuildSessionFactory();

            using (ISession s = sf.OpenSession())
            {
                object count = await(s.CreateQuery("select count(*) from Simple").UniqueResultAsync());
                Assert.IsTrue(count is Int64);
            }
            await(sf.CloseAsync());
        }
Пример #2
0
        public async Task HbmOrdererForgetsMappingFilesWithoutClassesIfExtendsIsUsedAsync()
        {
            Configuration cfg    = new Configuration();
            Assembly      domain = typeof(Master).Assembly;

            cfg.AddResource("NHibernate.DomainModel.MasterDetail.hbm.xml", domain);
            cfg.AddResource("NHibernate.DomainModel.MultiExtends.hbm.xml", domain);
            cfg.AddResource("NHibernate.DomainModel.Multi.hbm.xml", domain);
            cfg.AddResource("NHibernate.DomainModel.Query.hbm.xml", domain);

            ISessionFactory sf = cfg.BuildSessionFactory();

            try
            {
                using (ISession session = sf.OpenSession())
                {
                    Assert.IsNotNull(session.GetNamedQuery("AQuery"));
                }
            }
            finally
            {
                await(sf.CloseAsync());
            }
        }
 public Task CloseAsync(CancellationToken cancellationToken = new CancellationToken()) =>
 _inner.CloseAsync(cancellationToken);
Пример #4
0
 public Task CloseAsync(CancellationToken cancellationToken = new CancellationToken())
 {
     return(_sessionFactory.CloseAsync(cancellationToken));
 }
Пример #5
0
        public async Task CollectionFetchVsLoadAsync()
        {
            IStatistics stats = Sfi.Statistics;

            stats.Clear();

            ISession     s      = OpenSession();
            ITransaction tx     = s.BeginTransaction();
            Continent    europe = await(FillDbAsync(s));

            await(tx.CommitAsync());
            s.Clear();

            tx = s.BeginTransaction();
            Assert.AreEqual(0, stats.CollectionLoadCount);
            Assert.AreEqual(0, stats.CollectionFetchCount);
            Continent europe2 = await(s.GetAsync <Continent>(europe.Id));

            Assert.AreEqual(0, stats.CollectionLoadCount, "Lazy true: no collection should be loaded");
            Assert.AreEqual(0, stats.CollectionFetchCount);

            int cc = europe2.Countries.Count;

            Assert.AreEqual(1, stats.CollectionLoadCount);
            Assert.AreEqual(1, stats.CollectionFetchCount, "Explicit fetch of the collection state");
            await(tx.CommitAsync());
            s.Close();

            s  = OpenSession();
            tx = s.BeginTransaction();
            stats.Clear();
            europe = await(FillDbAsync(s));
            await(tx.CommitAsync());
            s.Clear();
            tx = s.BeginTransaction();
            Assert.AreEqual(0, stats.CollectionLoadCount);
            Assert.AreEqual(0, stats.CollectionFetchCount);

            europe2 = await(s.CreateQuery("from Continent a join fetch a.Countries where a.id = " + europe.Id).UniqueResultAsync <Continent>());
            Assert.AreEqual(1, stats.CollectionLoadCount);
            Assert.AreEqual(0, stats.CollectionFetchCount, "collection should be loaded in the same query as its parent");
            await(tx.CommitAsync());
            s.Close();

            Mapping.Collection coll = cfg.GetCollectionMapping("NHibernate.Test.Stats.Continent.Countries");
            coll.FetchMode = FetchMode.Join;
            coll.IsLazy    = false;
            ISessionFactory sf = cfg.BuildSessionFactory();

            stats = sf.Statistics;
            stats.Clear();
            stats.IsStatisticsEnabled = true;
            s      = sf.OpenSession();
            tx     = s.BeginTransaction();
            europe = await(FillDbAsync(s));
            await(tx.CommitAsync());
            s.Clear();
            tx = s.BeginTransaction();
            Assert.AreEqual(0, stats.CollectionLoadCount);
            Assert.AreEqual(0, stats.CollectionFetchCount);

            europe2 = await(s.GetAsync <Continent>(europe.Id));
            Assert.AreEqual(1, stats.CollectionLoadCount);
            Assert.AreEqual(0, stats.CollectionFetchCount,
                            "Should do direct load, not indirect second load when lazy false and JOIN");
            await(tx.CommitAsync());
            s.Close();
            await(sf.CloseAsync());

            coll           = cfg.GetCollectionMapping("NHibernate.Test.Stats.Continent.Countries");
            coll.FetchMode = FetchMode.Select;
            coll.IsLazy    = false;
            sf             = cfg.BuildSessionFactory();
            stats          = sf.Statistics;
            stats.Clear();
            stats.IsStatisticsEnabled = true;
            s      = sf.OpenSession();
            tx     = s.BeginTransaction();
            europe = await(FillDbAsync(s));
            await(tx.CommitAsync());
            s.Clear();
            tx = s.BeginTransaction();
            Assert.AreEqual(0, stats.CollectionLoadCount);
            Assert.AreEqual(0, stats.CollectionFetchCount);
            europe2 = await(s.GetAsync <Continent>(europe.Id));
            Assert.AreEqual(1, stats.CollectionLoadCount);
            Assert.AreEqual(1, stats.CollectionFetchCount, "Should do explicit collection load, not part of the first one");
            foreach (Country country in europe2.Countries)
            {
                await(s.DeleteAsync(country));
            }
            await(CleanDbAsync(s));
            await(tx.CommitAsync());
            s.Close();
        }
Пример #6
0
        public async Task TearDown()
        {
            await sessionFactory.CloseAsync();

            await schema.DropAsync(false, true);
        }
 public Task CloseAsync(CancellationToken cancellationToken = new CancellationToken())
 {
     return(_inner.CloseAsync(cancellationToken));
 }