protected override void Initialize() { var p1 = new ParentEntity(); var p2 = new ParentEntity(); var c1_1 = new Child1Entity(); var c1_2 = new Child1Entity(); var c2_1 = new Child2Entity(); var c2_2 = new Child2Entity(); allowNullInMiddleTable(); //rev 1 using (var tx = Session.BeginTransaction()) { p1_id = (int)Session.Save(p1); p2_id = (int)Session.Save(p2); c1_1_id = (int)Session.Save(c1_1); c1_2_id = (int)Session.Save(c1_2); c2_1_id = (int)Session.Save(c2_1); c2_2_id = (int)Session.Save(c2_2); tx.Commit(); } //rev 2 - (p1: c1_1, p2: c2_1) using (var tx = Session.BeginTransaction()) { p1.Children1.Add(c1_1); p2.Children2.Add(c2_1); tx.Commit(); } // Rev 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1) using (var tx = Session.BeginTransaction()) { p1.Children1.Add(c1_2); p1.Children2.Add(c2_2); p2.Children1.Add(c1_1); tx.Commit(); } // Revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2) using (var tx = Session.BeginTransaction()) { p1.Children1.Remove(c1_1); p2.Children2.Add(c2_2); tx.Commit(); } // Rev 5 - (p1: c2_2, p2: c1_1, c2_1) Session.Clear(); using (var tx = Session.BeginTransaction()) { c1_2 = Session.Get <Child1Entity>(c1_2.Id); c2_2 = Session.Get <Child2Entity>(c2_2.Id); c2_2.Parents.Remove(p2); c1_2.Parents.Remove(p1); tx.Commit(); } }
public async Task Many_children() { var queryString = @" { manyChildren { child1 { id } } }"; var parent = new WithManyChildrenEntity { Id = Guid.Parse("00000000-0000-0000-0000-000000000001"), }; var child1 = new Child1Entity { Id = Guid.Parse("00000000-0000-0000-0000-000000000002"), Parent = parent }; var child2 = new Child2Entity { Id = Guid.Parse("00000000-0000-0000-0000-000000000003"), Parent = parent }; parent.Child1 = child1; parent.Child2 = child2; var result = await RunQuery(queryString, null, parent, child1, child2); ObjectApprover.VerifyWithJson(result); }
public async Task Many_children() { var query = @" { manyChildren { child1 { id } } }"; var parent = new WithManyChildrenEntity(); var child1 = new Child1Entity { Parent = parent }; var child2 = new Child2Entity { Parent = parent }; parent.Child1 = child1; parent.Child2 = child2; using var database = await sqlInstance.Build(); var result = await RunQuery(database, query, null, null, parent, child1, child2); ObjectApprover.Verify(result); }
public async Task Many_children() { var query = @" { manyChildren { child1 { id } } }"; var parent = new WithManyChildrenEntity(); var child1 = new Child1Entity { Parent = parent }; var child2 = new Child2Entity { Parent = parent }; parent.Child1 = child1; parent.Child2 = child2; await using var database = await sqlInstance.Build(); await RunQuery(database, query, null, null, false, new object[] { parent, child1, child2 }); }
public async Task Many_children() { var query = @" { manyChildren { child1 { id } } }"; var parent = new WithManyChildrenEntity(); var child1 = new Child1Entity { Parent = parent }; var child2 = new Child2Entity { Parent = parent }; parent.Child1 = child1; parent.Child2 = child2; var result = await RunQuery(query, null, true, null, parent, child1, child2); ObjectApprover.VerifyWithJson(result); }
protected override void Initialize() { var intType = Dialect.GetTypeName(SqlTypeFactory.Int32); var tinyIntType = Dialect.GetTypeName(SqlTypeFactory.Byte); // We need first to modify the columns in the middle (join table) to allow null values. Hbm2ddl doesn't seem // to allow this. using (var tx = Session.BeginTransaction()) { Session.CreateSQLQuery("DROP TABLE children").ExecuteUpdate(); Session.CreateSQLQuery("CREATE TABLE children(parent_id " + intType + ", child1_id " + intType + ", child2_id " + intType + ")").ExecuteUpdate(); Session.CreateSQLQuery("DROP TABLE children_AUD").ExecuteUpdate(); Session.CreateSQLQuery("CREATE TABLE children_AUD(REV " + intType + " NOT NULL, REVEND " + intType + ", REVTYPE " + tinyIntType + ", " + "parent_id " + intType + ", child1_id " + intType + ", child2_id " + intType + ")").ExecuteUpdate(); tx.Commit(); } // Revision 1 using (var tx = Session.BeginTransaction()) { var p1 = new ParentEntity(); var p2 = new ParentEntity(); var c1_1 = new Child1Entity(); var c1_2 = new Child1Entity(); var c2_1 = new Child2Entity(); var c2_2 = new Child2Entity(); p1_id = (int)Session.Save(p1); p2_id = (int)Session.Save(p2); c1_1_id = (int)Session.Save(c1_1); c1_2_id = (int)Session.Save(c1_2); c2_1_id = (int)Session.Save(c2_1); c2_2_id = (int)Session.Save(c2_2); tx.Commit(); } Session.Clear(); // revision 2 - (p1: c1_1, p2: c2_1) using (var tx = Session.BeginTransaction()) { var p1 = Session.Get <ParentEntity>(p1_id); var p2 = Session.Get <ParentEntity>(p2_id); var c1_1 = Session.Get <Child1Entity>(c1_1_id); var c2_1 = Session.Get <Child2Entity>(c2_1_id); p1.Children1.Add(c1_1); p2.Children2.Add(c2_1); tx.Commit(); } Session.Clear(); // revision 3 - (p1: c1_1, c1_2, c2_2, p2: c1_1, c2_1) using (var tx = Session.BeginTransaction()) { var p1 = Session.Get <ParentEntity>(p1_id); var p2 = Session.Get <ParentEntity>(p2_id); var c1_1 = Session.Get <Child1Entity>(c1_1_id); var c1_2 = Session.Get <Child1Entity>(c1_2_id); var c2_2 = Session.Get <Child2Entity>(c2_2_id); p1.Children1.Add(c1_2); p1.Children2.Add(c2_2); p2.Children1.Add(c1_1); tx.Commit(); } Session.Clear(); // revision 4 - (p1: c1_2, c2_2, p2: c1_1, c2_1, c2_2) using (var tx = Session.BeginTransaction()) { var p1 = Session.Get <ParentEntity>(p1_id); var p2 = Session.Get <ParentEntity>(p2_id); var c1_1 = Session.Get <Child1Entity>(c1_1_id); var c2_2 = Session.Get <Child2Entity>(c2_2_id); p1.Children1.Remove(c1_1); p2.Children2.Add(c2_2); tx.Commit(); } Session.Clear(); // Revision 5 - (p1: c2_2, p2: c1_1, c2_1) using (var tx = Session.BeginTransaction()) { var p1 = Session.Get <ParentEntity>(p1_id); var p2 = Session.Get <ParentEntity>(p2_id); var c1_2 = Session.Get <Child1Entity>(c1_2_id); var c2_2 = Session.Get <Child2Entity>(c2_2_id); c2_2.Parents.Remove(p2); c1_2.Parents.Remove(p1); p2.Children2.Add(c2_2); tx.Commit(); } }