I am trying to solve a generic problem of users entering more data on a web form than the column can store (for
www.foodcandy.com). I could go through the schema and set some max length property on the control by hand of course, but I'd like to at least automate that or better, make it dynamic.
The first part is iterate through the schema and for each column find out its type, then for each (n)varchar type find out its max length. I can do this in MSSQL looking at the schema, etc., but this makes an assumption that I have a SQL driver. Anyone have any suggestions of how to do this generically in NHibernate?
Here's a start to enumerate objects and get the column names.
Code:
IDictionary metadata = Session.SessionFactory.GetAllClassMetadata();
foreach (DictionaryEntry entry in metadata)
{
Console.WriteLine(entry.Key);
SingleTableEntityPersister persister = (SingleTableEntityPersister) entry.Value;
Console.WriteLine(" table: {0}", persister.TableName);
foreach (string name in persister.PropertyNames)
{
Console.WriteLine(" property: {0}", name);
string[] columnnames = persister.GetColumnNames(name);
foreach (string columnname in columnnames)
{
Console.WriteLine(" column: {0}", columnname);
}
}
}
Thx
dB.