Esempio n. 1
0
		public void TestDeleteUsingHql()
		{
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				Person[] people = new Person[3];
				for (int i = 0; i < people.Length; i++)
				{
					people[i] = CreatePerson(string.Format("Person {0}", i + 1));
					s.Save(people[i]);
				}

				s.Flush();
				s.Clear();

				s.Delete("from Person");
				s.Flush();

				IList list = s.CreateQuery("from Person").List();
				Assert.AreEqual(0, list.Count);

				tx.Commit();
			}
		}
Esempio n. 2
0
		public void TestSequentialSelects()
		{
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				Employee mark = new Employee();
				mark.Name = "Mark";
				mark.Title = "internal sales";
				mark.Sex = 'M';
				mark.Address = "buckhead";
				mark.Zip = "30305";
				mark.Country = "USA";

				Customer joe = new Customer();
				joe.Name = "Joe";
				joe.Address = "San Francisco";
				joe.Zip = "54353";
				joe.Country = "USA";
				joe.Comments = "very demanding";
				joe.Sex = 'M';
				joe.Salesperson = mark;

				Person yomomma = new Person();
				yomomma.Name = "mom";
				yomomma.Sex = 'F';

				s.Save(yomomma);
				s.Save(mark);
				s.Save(joe);

				s.Flush();
				s.Clear();

				Person p = s.Get<Person>(yomomma.Id);
				Assert.AreEqual(yomomma.Name, p.Name);
				Assert.AreEqual(yomomma.Sex, p.Sex);
				s.Clear();

				// Copied from H3.  Don't really know what it is testing
				//Assert.AreEqual(0, s.CreateQuery("from System.Serializable").List().Count);

				Assert.AreEqual(3, s.CreateQuery("from Person").List().Count);
				Assert.AreEqual(1, s.CreateQuery("from Person p where p.class is null").List().Count);
				Assert.AreEqual(1, s.CreateQuery("from Person p where p.class = Customer").List().Count);
				Assert.AreEqual(1, s.CreateQuery("from Customer c").List().Count);
				s.Clear();

				IList customers = s.CreateQuery("from Customer c left join fetch c.Salesperson").List();
				foreach (Customer c in customers)
				{
					Assert.IsTrue(NHibernateUtil.IsInitialized(c.Salesperson));
					Assert.AreEqual("Mark", c.Salesperson.Name);
				}
				Assert.AreEqual(1, customers.Count);
				s.Clear();

				mark = (Employee) s.Get(typeof (Employee), mark.Id);
				joe = (Customer) s.Get(typeof (Customer), joe.Id);

				mark.Zip = "30306";
				s.Flush();
				s.Clear();
				Assert.AreEqual(1, s.CreateQuery("from Person p where p.Zip = '30306'").List().Count);

				tx.Commit();
			}
		}
Esempio n. 3
0
		protected bool PersonsAreEqual(Person x, Person y)
		{
			if (!string.Equals(x.Name, y.Name)) return false;
			if (x.Sex != y.Sex) return false;
			if (!string.Equals(x.Address, y.Address)) return false;
			if (!string.Equals(x.Zip, y.Zip)) return false;
			if (!string.Equals(x.Country, y.Country)) return false;
			if (!string.Equals(x.HomePhone, y.HomePhone)) return false;
			if (!string.Equals(x.BusinessPhone, y.BusinessPhone)) return false;
			if(x.OthersPhones.Count != y.OthersPhones.Count)
			{
				return false;
			}
			return true;
		}
Esempio n. 4
0
		private Person[] CreateAndInsertPersons(ISession s, int count)
		{
			Person[] result = new Person[count];

			for (int i = 0; i < count; i++)
			{
				result[i] = CreatePerson("Person " + i.ToString());
				s.Save(result[i]);
			}

			s.Flush();
			s.Clear();

			return result;
		}
Esempio n. 5
0
		private Person CreatePerson(string name)
		{
			Person p = new Person();
			p.Name = name;
			p.Sex = 'M';
			p.Address = "123 Some Street";
			p.Zip = "12345";
			p.Country = "Canada";
			p.HomePhone = "555-1234";
			p.BusinessPhone = "555-4321";
			p.OthersPhones = new HashSet<string> {"555-9876", "555-6789"};
			return p;
		}