Exemplo n.º 1
0
		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);
			}
		}
Exemplo n.º 2
0
 public void AddRelation(
     MapResultSet slaveResultSet,
     string slaveIndex,
     string masterIndex,
     string containerName)
 {
     AddRelation(slaveResultSet, new MapIndex(slaveIndex), new MapIndex(masterIndex), containerName);
 }
Exemplo n.º 3
0
		public MapRelation(
			MapResultSet slaveResultSet,
			MapIndex     slaveIndex,
			MapIndex     masterIndex,
			string       containerName)
			: base(slaveResultSet.ObjectType, slaveIndex, masterIndex, containerName)
		{
			_slaveResultSet  = slaveResultSet;
		}
Exemplo n.º 4
0
 public MapRelation(
     MapResultSet slaveResultSet,
     MapIndex slaveIndex,
     MapIndex masterIndex,
     string containerName)
     : base(slaveResultSet.ObjectType, slaveIndex, masterIndex, containerName)
 {
     _slaveResultSet = slaveResultSet;
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
			}
		}
Exemplo n.º 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));
		}
Exemplo n.º 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));
        }
Exemplo n.º 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);
					}
				}
			}
		}
Exemplo n.º 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);
			}
		}
Exemplo n.º 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);
		}
Exemplo n.º 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);
					}
				}
			}
		}
Exemplo n.º 13
0
 public void AddRelation(MapResultSet slaveResultSet, MapRelationBase relation)
 {
     AddRelation(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName);
 }
Exemplo n.º 14
0
 public MapRelation(MapResultSet slaveResultSet, MapRelationBase relation)
     : this(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName)
 {
 }
Exemplo n.º 15
0
		public void AddRelation(
			MapResultSet slaveResultSet,
			string       slaveIndex,
			string       masterIndex,
			string       containerName)
		{
			AddRelation( slaveResultSet, new MapIndex(slaveIndex), new MapIndex(masterIndex),containerName);
		}
Exemplo n.º 16
0
		public MapRelation(MapResultSet slaveResultSet, MapRelationBase relation)
			: this(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName)
		{ }
Exemplo n.º 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);
				}
			}
		}
Exemplo n.º 18
0
		public void AddRelation(MapResultSet slaveResultSet, MapRelationBase relation)
		{
			AddRelation(slaveResultSet, relation.SlaveIndex, relation.MasterIndex, relation.ContainerName);
		}