Exemple #1
0
		/// <summary>Creates a new code set.</summary>
		public CsDbCodeDataRow(CsDbCodeDataTable table)
		{
			Table = table;
			Columns = Architecture.Columns.Select(x => new CsDbcTableRow_Column(x, this)).ToArray();
			PkColumn = Columns.FirstOrDefault(x => x.Architecture == Architecture.PrimaryColumn);
			UnsignedColumns = Columns.Where(x => x.UnsignedVersion != null).Select(x => x.UnsignedVersion).ToArray();
		}
Exemple #2
0
		/// <summary>Creates the code base from an existing <see cref="CsDbArcDatabase" />.</summary>
		public static CsDbCodeBundleForDb FromArchitecture(CsDbCodeBundle owner, CsDbArcDatabase architecture)
		{
			var bundleForDb = new CsDbCodeBundleForDb(owner, architecture);
			bundleForDb.DataSet = new CsDbCodeDataSet(architecture, bundleForDb);

			var rvTables = new List<CsDbCodeDataTable>();
			var rvViews = new List<CsDbCodeDataView>();

			var columnMapping = new Dictionary<CsDbArcColumn, CsDbcTableRow_Column>();

			foreach (var table in architecture.Tables)
			{
				var rvTable = new CsDbCodeDataTable(table, bundleForDb);

				var columns = rvTable.Row.Columns.ToList();
				foreach (var archiColumn in table.Columns)
				{
					var codeColumn = columns.FirstOrDefault(x => x.Architecture == archiColumn);
					columnMapping.Add(archiColumn, codeColumn);
				}
				rvTables.Add(rvTable);
			}

			foreach (var view in architecture.Views)
			{
				var rvView = new CsDbCodeDataView(view, bundleForDb);
				rvViews.Add(rvView);
			}


			bundleForDb.Tables = rvTables.ToArray();
			bundleForDb.Views = rvViews.ToArray();

			foreach (var relation in architecture.Relations)
			{
				var pkColumn = columnMapping[relation.PrimaryKey];
				var fkColumn = columnMapping[relation.ForeignKey];
				var csDbCodeRelation = CsDbCodeRelation.Create(relation, pkColumn, fkColumn);
				csDbCodeRelation.ReferencingProperty = new CsDbcTableRow_ReferencingProperty(csDbCodeRelation);
				csDbCodeRelation.AssociatedProperty = new CsDbcTableRow_AssociatedProperty(csDbCodeRelation);
			}

			return bundleForDb;
		}