Esempio n. 1
0
		private void RecTransfer(CsDbTableRow sourceRow, CsDbRelation sourceRelation)
		{
			if (sourceRow == null)
				return;

			var sourceTable = sourceRow.Table;
			var targetTable = Target.GetTableByName(sourceTable.TableName);

			if (targetTable == sourceTable)
			{
				RecGoOverRelations(sourceRow, sourceRelation);
				return;
			}




			//Following next to lines should load the schema for the target table: targetTable.LoadSchema();
			if (targetTable.Columns.Count != sourceTable.Columns.Count)
				targetTable.Merge(sourceTable.Clone());

			if (targetTable.Generic_Find(sourceRow.PkValue) != null) return; // Skip if row is already in targetTable.

			targetTable.Rows.Add(sourceRow.ItemArray);
			RecGoOverRelations(sourceRow, sourceRelation);


		}
Esempio n. 2
0
		private void RecGoOverRelations(CsDbTableRow sourceRow, CsDbRelation sourceRelation)
		{
			var relations = sourceRow.GetRelations();
			foreach (var relation in relations)
			{
				if (relation == sourceRelation)
					continue;


				if (relation.PkTableName.Equals(sourceRow.Table.TableName))
				{
					foreach (CsDbTableRow fkRow in relation.GetFkRowsFromPkRow(sourceRow))
					{
						RecTransfer(fkRow, relation);
					}
				}
				else if (relation.FkTableName.Equals(sourceRow.Table.TableName))
				{
					RecTransfer(relation.GetPkRowFromFkRow(sourceRow), relation);
				}
				else throw new InvalidOperationException("This is not an expected state");
			}
		}