Quantcast
Channel: dbschemareader Discussions Rss Feed
Viewing all articles
Browse latest Browse all 166

New Post: changing tables once on the DatabaseSchema

$
0
0
It is possible to just set the databasetable.NetName property. This is sufficient for simple changes before code generation.
var docStatusTable = schema.FindTableByName("DocumentStatus");
docStatusTable.NetName = "DocState";
var productsTableAgain = schema.FindTableByName("DocumentStatus"); //find it again (second reference)
Console.WriteLine(docStatusTableAgain.NetName); //shows "DocState"
Changing the actual name (databasetable.Name) is more problematic, although this is only a problem for DDL generation, not code generation. The foreign key constraints may keep the old name (in the string properties- TableName) although the reference properties will be correct. There are also references in views, stored procedures, triggers and the like- and those are way beyond the scope of this little project.

For more extensive changes, there is a mechanism via CodeWriterSettings - it has a Namer property, and you can either implement the INamer interface, or more practically override the base Namer class with customizations. The simplest is to override the Namer.Name(string) signature. In the library, the PluralizingNamer is in fact a class that inherits from Namer and overrides it.

Removing a table should be done with the schema.RemoveTable(string) extension method.
schema.RemoveTable("sysdiagrams");
If you just do schema.Tables.Remove(table), all the foreign key associations still point to the missing table and the code generation will probably just fail. The RemoveTable extension cleans up the foreign keys first, so the code generation will still work cleanly.

Viewing all articles
Browse latest Browse all 166

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>