kellyb
kellyb

Reputation: 1371

How to get a list of all of my entities mapped tables?

In short: how do I get a list of all the of the table names that are mapped to my entities?

Why: We have a set of WCF web services backed by NHibernate mapped via FluentNHibernate. We built a simple yet powerful health checking capabilities into our architecture. We can call a secured Diagnose() service operation, and it asks our Windsor container for all registered instances of our IHealthCheck interface. We have a number of concrete implementations of this interface that check the state of our product's installation - i.e. database connectivity, seed data, down string service connectivity, etc. etc.

We've build a number of things that check the health of our NHibernate code. For example we borrowed this [1] code form Ayende to query each mapping. I would like to build a check around our custom KeyGenerator implementation that we're using with NHibernate. We have a table that stores a row per table in our database. Our HILO algorithm uses that table to perform it's key generation. So, I would like to write a check that confirms that every mapped entity in our SessionFactory has a row in that table that represents the entities backing table.

Any pointers would be appreciated. session.SessionFactory.GetAllClassMetadata() smells promising, but I can't see to find exactly what I'm looking for.

Cheers.

[1] http://ayende.com/Blog/archive/2006/08/09/NHibernateMappingCreatingSanityChecks.aspx

Upvotes: 2

Views: 1503

Answers (1)

Jason Freitas
Jason Freitas

Reputation: 1585

I've done the same thing by keeping a reference to the NHibernate.Cfg.Configuration I use to build the SessionFactory with.

It has a ClassMappings collection which contains a PersistentClass object for each entity. The PersistentClass.Table.Name property should be what you're looking for.

Upvotes: 5

Related Questions