+ command.CommandText = "DELETE from parent_history;"; command.ExecuteNonQuery(); command.CommandText = "DELETE from parent;"; command.ExecuteNonQuery(); } } [Test] public void KnownFailure_Correct_Id_Returned_When_Using_Trigger() { Assert.Throws<AssertionException>(() => RunTest(), "We expected this test to fail - if the problem has been fixed, clean-up the test."); } private void RunTest() { var entity1 = new Parent {Name = "Parent1_0"}; // when saved this entity should have the id of 1 var entity2 = new Parent {Name = "Parent2_0"}; // when saved this entity should have the id of 2 var entity3 = new Parent {Name = "Parent3_0"}; // when saved this entity should have the id of 3 using (ISession s = OpenSession()) { // save first entity s.Save(entity1); s.Flush(); Assert.AreEqual(1, entity1.Id); // save second entity s.Save(entity2); s.Flush(); Assert.AreEqual(2, entity2.Id); // update this entity 10 times - adds entries to the audit table // causing the sequences for the parent and history table to no longer be aligned for (int i = 1; i < 11; i++) { entity2.Name = string.Format("Parent2_{0}", i); s.Update(entity2); s.Flush(); } // save third entity s.Save(entity3); s.Flush(); Assert.AreEqual( 3, entity3.Id, "oh uh - it would appear that lastval() is not our friend when a trigger updates other sequences."); // now would be a good time to look at the data in the tables and see that they have the IDs as expected // which are not the same as those returned by nhibernate } } }}
0 commit comments