public void Test1() { List<Parent> parents = new List<Parent>(); MapResultSet[] sets = new MapResultSet[2]; sets[0] = new MapResultSet(typeof(Parent), parents); sets[1] = new MapResultSet(typeof(Child)); sets[0].AddRelation(sets[1], "ParentID", "ParentID", "Children"); sets[1].AddRelation(sets[0], "ParentID", "ParentID", "Parent"); using (DbManager db = new DbManager()) { db .SetCommand(_parentChildquery) .ExecuteResultSet(sets); } foreach (Parent p in parents) { Assert.That(p.IsDirty == false); foreach (Child c in p.Children) Assert.That(c.IsDirty == false); } }
public void AddRelation( MapResultSet slaveResultSet, string slaveIndex, string masterIndex, string containerName) { AddRelation(slaveResultSet, new MapIndex(slaveIndex), new MapIndex(masterIndex), containerName); }
public MapRelation( MapResultSet slaveResultSet, MapIndex slaveIndex, MapIndex masterIndex, string containerName) : base(slaveResultSet.ObjectType, slaveIndex, masterIndex, containerName) { _slaveResultSet = slaveResultSet; }
internal MapResultSet(MapResultSet resultSet) { _objectType = resultSet._objectType; _parameters = resultSet._parameters; if (resultSet._relationList != null) { _relationList = new List <MapRelation>(resultSet._relationList.Count); _relationList.AddRange(resultSet._relationList); } }
internal MapResultSet(MapResultSet resultSet) { _objectType = resultSet._objectType; _parameters = resultSet._parameters; if (resultSet._relationList != null) { _relationList = new List<MapRelation>(resultSet._relationList.Count); _relationList.AddRange(resultSet._relationList); } }
public void AddRelation( MapResultSet slaveResultSet, MapIndex slaveIndex, MapIndex masterIndex, string containerName) { if (_relationList == null) _relationList = new List<MapRelation>(); _relationList.Add(new MapRelation(slaveResultSet, slaveIndex, masterIndex, containerName)); }
public void AddRelation( MapResultSet slaveResultSet, MapIndex slaveIndex, MapIndex masterIndex, string containerName) { if (_relationList == null) { _relationList = new List <MapRelation>(); } _relationList.Add(new MapRelation(slaveResultSet, slaveIndex, masterIndex, containerName)); }
public void Test() { List<Parent> parents = new List<Parent>(); /*[a]*/MapResultSet/*[/a]*/[] sets = new MapResultSet[3]; sets[0] = new MapResultSet(typeof(Parent), parents); sets[1] = new MapResultSet(typeof(Child)); sets[2] = new MapResultSet(typeof(Grandchild)); sets[0].AddRelation(sets[1], "ParentID", "ParentID", "Children"); sets[1].AddRelation(sets[0], "ParentID", "ParentID", "Parent"); sets[1].AddRelation(sets[2], "ChildID", "ChildID", "Grandchildren"); sets[2].AddRelation(sets[1], "ChildID", "ChildID", "Child"); using (DbManager db = new DbManager()) { db .SetCommand (TestQuery) ./*[a]*/ExecuteResultSet/*[/a]*/(sets); } Assert.IsNotEmpty(parents); foreach (Parent parent in parents) { Assert.IsNotNull(parent); Assert.IsNotEmpty(parent.Children); foreach (Child child in parent.Children) { Assert.AreEqual(parent, child.Parent); Assert.IsNotEmpty(child.Grandchildren); foreach (Grandchild grandchild in child.Grandchildren) { Assert.AreEqual(child, grandchild.Child); Assert.AreEqual(parent, grandchild.Child.Parent); } } } }
public void TestFailResultSet1() { MapResultSet[] sets = new MapResultSet[2]; sets[0] = new MapResultSet(typeof(Master)); sets[1] = new MapResultSet(typeof(Slave)); sets[0].AddRelation(sets[1], "MasterID", "ID", "Slaves"); using (DbManager db = new DbManager()) { db #if ORACLE .SetSpCommand("ResultSetTest") #else .SetCommand(SqlResultSet) #endif .ExecuteResultSet(sets); } }
public void TestResultSet() { MapResultSet[] sets = new MapResultSet[2]; sets[0] = new MapResultSet(typeof(Master)); sets[1] = new MapResultSet(typeof(Slave)); sets[0].AddRelation(sets[1], "MasterID", "MasterID", "Slaves"); using (DbManager db = new DbManager()) { db #if ORACLE .SetSpCommand("ResultSetTest") #else .SetCommand(SqlResultSet) #endif .ExecuteResultSet(sets); } Assert.AreEqual(7, ((Slave)(((Master)sets[0].List[0]).Slaves[1])).ID); }
public void Test3() { var parents = new List<ParentEx>(); var sets = new /*[a]*/MapResultSet/*[/a]*/[3]; sets[0] = new MapResultSet(typeof(ParentEx), parents); sets[1] = new MapResultSet(typeof(ChildEx)); sets[2] = new MapResultSet(typeof(GrandchildEx)); using (var db = new DbManager()) { db.MappingSchema = _mappingSchema; db .SetCommand(TestQuery) ./*[a]*/ExecuteResultSet/*[/a]*/(sets); } Assert.IsNotEmpty(parents); foreach (ParentEx parent in parents) { Assert.IsNotNull(parent); Assert.IsNotEmpty(parent.Children); foreach (ChildEx child in parent.Children) { Assert.AreEqual(parent, child.Parent); Assert.IsNotEmpty(child.Grandchildren); foreach (GrandchildEx grandchild in child.Grandchildren) { Assert.AreEqual(child, grandchild.Child); Assert.AreEqual(parent, grandchild.Child.Parent); } } } }
public void AddRelation(MapResultSet slaveResultSet, MapRelationBase relation) { AddRelation(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName); }
public MapRelation(MapResultSet slaveResultSet, MapRelationBase relation) : this(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName) { }
public void AddRelation( MapResultSet slaveResultSet, string slaveIndex, string masterIndex, string containerName) { AddRelation( slaveResultSet, new MapIndex(slaveIndex), new MapIndex(masterIndex),containerName); }
public void ShouldMapRelationForChild() { // given List<Parent2Child> parents = new List<Parent2Child>(); MapResultSet[] sets = new MapResultSet[2]; sets[0] = new MapResultSet(typeof(Parent2Child), parents); sets[1] = new MapResultSet(typeof(Child2)); // db config var conn = new MockDb() .NewReader("ParentID") .NewRow(1) .NewRow(2) .NextResult("ChildID", "ParentID") .NewRow(4, 1) .NewRow(5, 2) .NewRow(6, 2) .NewRow(7, 1); using (conn) using (var db = new DbManager(conn)) { // fluent config new FluentMap<Parent2>() .MapField(_ => _.ID, "ParentID").PrimaryKey() .MapField(_ => _.Children).Relation() .MapTo(db); new FluentMap<Child2>() .MapField(_ => _.Parent.ID, "ParentID") .MapField(_ => _.ID, "ChildID").PrimaryKey() .MapField(_ => _.Parent).Relation() .MapTo(db); // when db.SetCommand("select *").ExecuteResultSet(sets); } // then Assert.IsTrue(parents.Any()); foreach (Parent2Child parent in parents) { Assert.IsNotNull(parent); Assert.IsTrue(parent.Children.Any()); foreach (Child2 child in parent.Children) { Assert.AreEqual(parent, child.Parent); } } }