sni*_*ker 7 c# nhibernate nhibernate-mapping
一旦我在NHibernate中映射了我的域,我怎样才能在我的代码中的其他地方反向查找这些映射?
例:
由于Pony某种原因,该实体被映射到名为"AAZF1203"的表.(愚蠢的遗留数据库表名!)我想只使用typeof(Pony)因为我必须在其他地方编写查询来从NH映射中找出该表名.
private const string LegacyPonyTableName = "AAZF1203";
[Test]
public void MakeSureThatThePonyEntityIsMappedToCorrectTable()
{
string ponyTable = GetNHibernateTableMappingFor(typeof(Pony));
Assert.AreEqual(LegacyPonyTableName, ponyTable);
}
Run Code Online (Sandbox Code Playgroud)
换句话说,GetNHibernateTableMappingFor(Type t)需要看起来像什么?
Die*_*hon 13
那时你需要那些信息吗?
因为这取决于你拥有的......
不久前我必须从审计事件监听器获取表名,我使用了这个:
IPostDatabaseOperationEventArgs args //parameter
var tableName = ((ILockable)args.Persister).RootTableName.ToLower();
Run Code Online (Sandbox Code Playgroud)
你也可以从会议中得到它......
((ILockable)session.GetSessionImplementation()
.GetEntityPersister(null, new Pony())).RootTableName
Run Code Online (Sandbox Code Playgroud)