Thanks for the reply. There already is an instance in the database. The code below should illustrate the problem. Using SaveOrUpdateCopy the test fails for the code in session 2. If it is modified to use SaveOrUpdate it passes.
What I found from this test is that the return value of SaveOrUpdateCopy has updated version fields, while the input still has the old version. However, when the initial version of the object is saved (in session 1) the database id of the input is updated, which leads me to believe that the behaviour is unexpected.
Any thoughts?
Regards
Martin
Code:
[TestMethod]
public void UsingSaveOrUpdateCopy()
{
// Session 1:
BidirectionalParent parent = new BidirectionalParent(0, "Paul");
BidirectionalChild child = parent.AddChild("Simone");
using (ISession session = this.factory.OpenSession())
{
session.SaveOrUpdateCopy(parent);
session.Flush();
}
Assert.AreNotEqual(0, parent.Id, "Expected parent id to be set");
Assert.AreEqual(0, parent.Version, "Expected parent version to be 0");
Assert.AreNotEqual(0, child.Id, "Expected child id to be set");
Assert.AreEqual(0, child.Version, "Expected child version to be 0");
Int32 parentID = parent.Id;
Int32 childID = child.Id;
// Session 2:
parent.Name = "Frank";
child.Name = "Maria";
BidirectionalParent result;
using (ISession session = this.factory.OpenSession())
{
result = (BidirectionalParent)session.SaveOrUpdateCopy(parent);
session.Flush();
}
Assert.AreEqual(parentID, result.Id, "Expected parent id to be unchanged after edit (return value)");
Assert.AreEqual(1, result.Version, "Expected parent version to be 1 after edit (return value)");
Assert.AreEqual(childID, result.GetChild(0).Id, "Expected child id to be unchanged after edit (return value)");
Assert.AreEqual(1, result.GetChild(0).Version, "Expected child version to be 1 after edit (return value)");
Assert.AreEqual(parentID, parent.Id, "Expected parent id to be unchanged after edit (input value)");
// This assertion fails:
Assert.AreEqual(1, parent.Version, "Expected parent version to be 1 after edit (input value)");
Assert.AreEqual(childID, child.Id, "Expected child id to be unchanged after edit (input value)");
Assert.AreEqual(1, child.Version, "Expected child version to be 1 after edit (input value)");
}