autoflushtestfixture.cs

来自「NHibernate NET开发者所需的」· CS 代码 · 共 42 行

CS
42
字号
using System.Collections;
using NHibernate.Criterion;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH830
{
	[TestFixture]
	public class AutoFlushTestFixture : BugTestCase
	{
		[Test]
		public void AutoFlushTest()
		{
			ISession sess = OpenSession();
			ITransaction t = sess.BeginTransaction();
			//Setup the test data
			Cat mum = new Cat();
			Cat son = new Cat();
			sess.Save(mum);
			sess.Save(son);
			sess.Flush();

			//reload the data and then setup the many-to-many association
			mum = (Cat) sess.Get(typeof(Cat), mum.Id);
			son = (Cat) sess.Get(typeof(Cat), son.Id);
			mum.Children.Add(son);
			son.Parents.Add(mum);

			//Use criteria API to search first 
			IList result = sess.CreateCriteria(typeof(Cat))
				.CreateAlias("Children", "child")
				.Add(Expression.Eq("child.Id", son.Id))
				.List();
			//the criteria failed to find the mum cat with the child
			Assert.AreEqual(1, result.Count);

			sess.Delete(mum);
			sess.Delete(son);
			t.Commit();
			sess.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?