public void TestLoadChildFirst() { int parentId = 0; int childId = 0; using (ISession s1 = OpenSession()) using (ITransaction t1 = s1.BeginTransaction()) { // create a new LLParent parent = new LLParent(); LLChildNoAdd child = new LLChildNoAdd(); parent.ChildrenNoAdd.Add(child); child.Parent = parent; s1.Save(parent); parentId = (int)s1.GetIdentifier(parent); childId = (int)s1.GetIdentifier(child); t1.Commit(); } // try to Load the object to make sure the save worked using (ISession s2 = OpenSession()) using (ITransaction t2 = s2.BeginTransaction()) { LLChildNoAdd child2 = (LLChildNoAdd)s2.Load(typeof(LLChildNoAdd), childId); Assert.AreEqual(parentId, (int)s2.GetIdentifier(child2.Parent)); } }
public void TestLazyLoadNoAdd() { int parentId = 0; using (ISession s1 = OpenSession()) using (ITransaction t1 = s1.BeginTransaction()) { // create a new LLParent parent = new LLParent(); LLChildNoAdd child = new LLChildNoAdd(); parent.ChildrenNoAdd.Add(child); child.Parent = parent; s1.Save(parent); parentId = (int)s1.GetIdentifier(parent); t1.Commit(); } // try to Load the object to make sure the save worked using (ISession s2 = OpenSession()) using (ITransaction t2 = s2.BeginTransaction()) { LLParent parent2 = (LLParent)s2.Load(typeof(LLParent), parentId); Assert.AreEqual(1, parent2.ChildrenNoAdd.Count); } using (ISession session = sessions.OpenSession()) { session.Delete("from LLParent"); session.Flush(); } }
public async Task TestLoadParentFirstAsync() { int parentId = 0; using (ISession s1 = OpenSession()) using (ITransaction t1 = s1.BeginTransaction()) { // create a new LLParent parent = new LLParent(); LLChildNoAdd child = new LLChildNoAdd(); parent.ChildrenNoAdd.Add(child); child.Parent = parent; await(s1.SaveAsync(parent)); parentId = (int)s1.GetIdentifier(parent); await(t1.CommitAsync()); } // try to Load the object to make sure the save worked using (ISession s2 = OpenSession()) using (ITransaction t2 = s2.BeginTransaction()) { LLParent parent2 = (LLParent)await(s2.LoadAsync(typeof(LLParent), parentId)); Assert.AreEqual(1, parent2.ChildrenNoAdd.Count); } }