Fabio,
Yes. I actually got my solution by debugging through the SchemaValidator.cs
source in the NHibernate trunk. The key was calling cfg.BuildMappings(),
which ensured the Configuration object is completely build (it's not built
right away) - fully built.
Below is a snippet of grabbing every table (which contains every column)
Configuration cfg = //get config
cfg.BuildMappings(); //VERY IMPORTANT
var set = new HashedSet<Table>();
int totalColumnCount = 0;
foreach (var classMapping in cfg.ClassMappings)
{
Table table = classMapping.Table;
set.Add(table);
}
foreach (var collectionMapping in cfg.CollectionMappings)
{
Table table = collectionMapping.CollectionTable;
if (table == null)
{
table = collectionMapping.Table;
}
set.Add(table);
}
var list = new List<Table>(set);
list.Sort((x, y) => x.Name.CompareTo(y.Name));
foreach (var table in list)
{
Console.WriteLine("TABLE: {0}", table.Name);
totalColumnCount += table.ColumnIterator.Count();
foreach (var column in table.ColumnIterator)
{
Type returnedClass = column.Value.Type.ReturnedClass;
Console.WriteLine("COLUMN: {0} - TYPE: {1}",
column.Name, returnedClass);
}
}
Console.WriteLine("Number of tables: {0} - total columns {1}",
list.Count, totalColumnCount);
Best regards,
Jeffrey Palermo, Microsoft MVP, MCSD.Net
CTO, Headspring Systems
agile. software. consulting.
512-459-2260 x 712
On Mon, Dec 1, 2008 at 3:13 PM, Fabio Maulo <[EMAIL PROTECTED]> wrote:
> 2008/12/1 Jeffrey Palermo <[EMAIL PROTECTED]>
>
>>
>> Has anyone already written this routine to loop through to discover all
>> the mapped properties to table/columns? If so, would you mind sharing?
>>
>>
> Are you talking about something like this ?
> http://nhforge.org/blogs/nhibernate/archive/2008/11/22/nhibernate-schemavalidator.aspx
>
> --
> Fabio Maulo
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---