How to look up an NHibernate entity's table mapping from the type of the entity?

Posted by snicker on Stack Overflow See other posts from Stack Overflow or by snicker
Published on 2010-03-11T23:55:39Z Indexed on 2010/03/19 23:21 UTC
Read the original article Hit count: 207

Filed under:
|
|

Once I've mapped my domain in NHibernate, how can I reverse lookup those mappings somewhere else in my code?

Example:

The entity Pony is mapped to a table named "AAZF1203" for some reason. (Stupid legacy database table names!) I want to find out that table name from the NH mappings using only the typeof(Pony) because I have to write a query elsewhere.

How can I make the following test pass?

private const string LegacyPonyTableName = "AAZF1203";

[Test]
public void MakeSureThatThePonyEntityIsMappedToCorrectTable()
{
    string ponyTable = GetNHibernateTableMappingFor(typeof(Pony));
    Assert.AreEqual(LegacyPonyTableName, ponyTable);
}

In other words, what does the GetNHibernateTableMappingFor(Type t) need to look like?

© Stack Overflow or respective owner

Related posts about c#

Related posts about nhibernate