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);
			}
		}
示例#2
0
 public void AddRelation(
     MapResultSet slaveResultSet,
     string slaveIndex,
     string masterIndex,
     string containerName)
 {
     AddRelation(slaveResultSet, new MapIndex(slaveIndex), new MapIndex(masterIndex), containerName);
 }
示例#3
0
		public MapRelation(
			MapResultSet slaveResultSet,
			MapIndex     slaveIndex,
			MapIndex     masterIndex,
			string       containerName)
			: base(slaveResultSet.ObjectType, slaveIndex, masterIndex, containerName)
		{
			_slaveResultSet  = slaveResultSet;
		}
示例#4
0
 public MapRelation(
     MapResultSet slaveResultSet,
     MapIndex slaveIndex,
     MapIndex masterIndex,
     string containerName)
     : base(slaveResultSet.ObjectType, slaveIndex, masterIndex, containerName)
 {
     _slaveResultSet = slaveResultSet;
 }
示例#5
0
        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);
            }
        }
示例#6
0
		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);
			}
		}
示例#7
0
		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));
		}
示例#8
0
        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));
        }
示例#9
0
		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);
					}
				}
			}
		}
示例#10
0
		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);
			}
		}
示例#11
0
		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);
		}
示例#12
0
		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);
					}
				}
			}
		}
示例#13
0
 public void AddRelation(MapResultSet slaveResultSet, MapRelationBase relation)
 {
     AddRelation(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName);
 }
示例#14
0
 public MapRelation(MapResultSet slaveResultSet, MapRelationBase relation)
     : this(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName)
 {
 }
示例#15
0
		public void AddRelation(
			MapResultSet slaveResultSet,
			string       slaveIndex,
			string       masterIndex,
			string       containerName)
		{
			AddRelation( slaveResultSet, new MapIndex(slaveIndex), new MapIndex(masterIndex),containerName);
		}
示例#16
0
		public MapRelation(MapResultSet slaveResultSet, MapRelationBase relation)
			: this(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName)
		{ }
示例#17
0
		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);
				}
			}
		}
示例#18
0
		public void AddRelation(MapResultSet slaveResultSet, MapRelationBase relation)
		{
			AddRelation(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName);
		}