예제 #1
0
		public void StoreWithLinksAndLookup()
		{
			Apple apple = new Apple();
			Fruit fruit = new Fruit();

			apple.TheFruit = fruit;
			fruit.TheApple = apple;

			using (ISession session = OpenSession())
			using (ITransaction tx = session.BeginTransaction())
			{
				session.Save(apple);
				session.Save(fruit);

				tx.Commit();
			}

			using (ISession session = OpenSession())
			using (ITransaction tx = session.BeginTransaction())
			{
				Apple apple2 = (Apple) session.Get(typeof(Apple), apple.Id);
				Fruit fruit2 = (Fruit) session.Get(typeof(Fruit), fruit.Id);

				Assert.IsNotNull(apple2);
				Assert.IsNotNull(fruit2);

				Assert.AreSame(apple2, fruit2.TheApple);
				Assert.AreSame(fruit2, apple2.TheFruit);
				tx.Commit();
			}
		}
예제 #2
0
        public void StoreAndLookup()
        {
            Apple apple = new Apple();
            Fruit fruit = new Fruit();

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    session.Save(apple);
                    session.Save(fruit);

                    Assert.IsNotNull(session.Get(typeof(Apple), apple.Id));
                    Assert.IsNotNull(session.Get(typeof(Fruit), fruit.Id));

                    tx.Commit();
                }
        }
예제 #3
0
        public async Task StoreAndLookupAsync()
        {
            Apple apple = new Apple();
            Fruit fruit = new Fruit();

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    await(session.SaveAsync(apple));
                    await(session.SaveAsync(fruit));

                    Assert.IsNotNull(await(session.GetAsync(typeof(Apple), apple.Id)));
                    Assert.IsNotNull(await(session.GetAsync(typeof(Fruit), fruit.Id)));

                    await(tx.CommitAsync());
                }
        }
예제 #4
0
		public void StoreAndLookup()
		{
			Apple apple = new Apple();
			Fruit fruit = new Fruit();

			using (ISession session = OpenSession())
			using (ITransaction tx = session.BeginTransaction())
			{
				session.Save(apple);
				session.Save(fruit);

				Assert.IsNotNull(session.Get(typeof(Apple), apple.Id));
				Assert.IsNotNull(session.Get(typeof(Fruit), fruit.Id));

				tx.Commit();
			}
		}
예제 #5
0
		public void StoreWithLinksAndLookupWithQueryFromFruit()
		{
			Apple apple = new Apple();
			Fruit fruit = new Fruit();

			apple.TheFruit = fruit;
			fruit.TheApple = apple;

			using (ISession session = OpenSession())
			using (ITransaction tx = session.BeginTransaction())
			{
				session.Save(apple);
				session.Save(fruit);
				tx.Commit();
			}

			using (ISession session = OpenSession())
			using (ITransaction tx = session.BeginTransaction())
			{
				Fruit fruit2 = (Fruit) session.Get(typeof(Fruit), fruit.Id);
				Assert.IsNotNull(fruit2);
				IList results = session
					.CreateQuery("from Apple a where a.TheFruit = ?")
					.SetParameter(0, fruit2)
					.List();

				Assert.AreEqual(1, results.Count);
				Apple apple2 = (Apple) results[0];
				Assert.IsNotNull(apple2);

				Assert.AreSame(apple2, fruit2.TheApple);
				Assert.AreSame(fruit2, apple2.TheFruit);
				tx.Commit();
			}
		}