I'm not sure if there's another way, but to get at entity mapping metadata, we hold on to the NHibnerate.Cfg.Configuration object that's used to create the session factory, and expose it in our entity service singleton along with the session factory. Then we can do things like this:
Code:
NHibernate.Mapping.PersistentClass persistentClass =
configuration.GetClassMapping(entityType);
if (persistentClass == null)
{
throw new NHibernate.MappingException(
string.Format("Mapping for class '{0}' not found",
entityType.AssemblyQualifiedName));
}
NHibernate.Mapping.Property idProperty = persistentClass.IdentifierProperty;
NHibernate.Mapping.Column idColumn = null;
foreach (NHibernate.Mapping.Column column in idProperty.ColumnCollection)
{
// we assume here that the identifier property
// is backed by one column
idColumn = column;
break;
}
From there you can get all kinds of information on mapped properties and the columns that back them.