예제 #1
0
		/// <summary>Creates the code bundle from an existing <see cref="CsDbArchitecture" />.</summary>
		internal static CsDbCodeBundle FromArchitecture(CsDbArchitecture architecture)
		{
			var codeBundle = new CsDbCodeBundle(architecture);

			codeBundle.Context = new CsDbCodeDataContext(codeBundle);
			codeBundle.Databases = architecture.Databases.Select(x => CsDbCodeBundleForDb.FromArchitecture(codeBundle, x)).ToArray();

			return codeBundle;
		}
예제 #2
0
		internal CsDbCodeBundleWriter(CsDbCodeBundle codeBundle)
		{
			CodeBundle = codeBundle;
		}
예제 #3
0
		private CsDbCodeBundleForDb(CsDbCodeBundle owner, CsDbArcDatabase architecture)
		{
			Owner = owner;
			Architecture = architecture;
		}
예제 #4
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;
		}