예제 #1
0
		public void ManyToOneId()
		{
			Building madison = new Building();
			madison.Id = 1;
			madison.Number = "4800";

			Building college = new Building();
			college.Id = 2;
			college.Number = "6363";

			Office acctg = new Office();
			acctg.Id = 3;
			acctg.Worker = "Bean Counter";
			acctg.Location = college;

			Office hr = new Office();
			hr.Id = 4;
			hr.Worker = "benefits";
			hr.Location = madison;

			Office it = new Office();
			hr.Id = 5;
			it.Worker = "servers";
			it.Location = madison;

			ISession s = OpenSession();
			s.Save(madison);
			s.Save(college);
			s.Save(acctg);
			s.Save(hr);
			s.Save(it);
			s.Flush();
			s.Close();

			s = OpenSession();

			ICriteria c = s.CreateCriteria(typeof(Office));
			c.Add(Expression.Eq("Location.Id", madison.Id));
			IList results = c.List();

			Assert.AreEqual(2, results.Count, "2 objects");
			foreach (Office office in results)
			{
				Assert.AreEqual(madison.Id, office.Location.Id, "same location as criteria specified");
			}

			c = s.CreateCriteria(typeof(Office));
			c.Add(Expression.Eq("Location.Id", college.Id));
			results = c.List();

			Assert.AreEqual(1, results.Count, "1 objects");
			foreach (Office office in results)
			{
				Assert.AreEqual(college.Id, office.Location.Id, "same location as criteria specified");
			}

			s.Delete("from Office ");
			s.Delete("from Building");
			s.Flush();
			s.Close();
		}
예제 #2
0
파일: Fixture.cs 프로젝트: jrauber/GH1429
        public async Task ManyToOneIdAsync()
        {
            Building madison = new Building();

            madison.Id     = 1;
            madison.Number = "4800";

            Building college = new Building();

            college.Id     = 2;
            college.Number = "6363";

            Office acctg = new Office();

            acctg.Id       = 3;
            acctg.Worker   = "Bean Counter";
            acctg.Location = college;

            Office hr = new Office();

            hr.Id       = 4;
            hr.Worker   = "benefits";
            hr.Location = madison;

            Office it = new Office();

            hr.Id       = 5;
            it.Worker   = "servers";
            it.Location = madison;

            ISession s = OpenSession();

            await(s.SaveAsync(madison));
            await(s.SaveAsync(college));
            await(s.SaveAsync(acctg));
            await(s.SaveAsync(hr));
            await(s.SaveAsync(it));
            await(s.FlushAsync());
            s.Close();

            s = OpenSession();

            ICriteria c = s.CreateCriteria(typeof(Office));

            c.Add(Expression.Eq("Location.Id", madison.Id));
            IList results = await(c.ListAsync());

            Assert.AreEqual(2, results.Count, "2 objects");
            foreach (Office office in results)
            {
                Assert.AreEqual(madison.Id, office.Location.Id, "same location as criteria specified");
            }

            c = s.CreateCriteria(typeof(Office));
            c.Add(Expression.Eq("Location.Id", college.Id));
            results = await(c.ListAsync());

            Assert.AreEqual(1, results.Count, "1 objects");
            foreach (Office office in results)
            {
                Assert.AreEqual(college.Id, office.Location.Id, "same location as criteria specified");
            }

            await(s.DeleteAsync("from Office "));
            await(s.DeleteAsync("from Building"));
            await(s.FlushAsync());
            s.Close();
        }