-1

像这样映射一个包:

<bag name="Addresses" table="address" cascade="all-delete-orphan">
  <key column="employee"/>
  <element column="address"/>
</bag>

如何在运行时获取存储地址的表名?

如果集合泛型类型是 NHibernate 映射类,我可以这样做:

var tableName = (sessionFactory.GetClassMetadata(itemType) as SingleTableEntityPersister).TableName;

但在这种情况下,集合泛型类型只是一个字符串,我找不到任何方法从元数据中检索表名。

谢谢你的帮助!

4

2 回答 2

1

知道你在哪里需要这个会很有趣。尽管如此

var metaData = sf.GetClassMetadata("containingType");
var c = (CollectionType)metaData.PropertyTypes[Array.IndexOf(metaData.PropertyNames, "collectionPropertyName")];
var tablename = c.GetAssociatedJoinable((ISessionFactoryImplementor)sf).TableName;
于 2012-08-14T08:18:22.587 回答
0

Another possible solution:

var classMetadata= sessionFactory.GetClassMetadata(typeof(parentClass)) as SingleTableEntityPersister;
var key = classMetadata.RootEntityName + "." + propertyName;
var allCollectionMetadata = sessionFactory.GetAllCollectionMetadata();
var childTableName = (allCollectionMetadata[key] as BasicCollectionPersister).TableName;
于 2012-08-16T10:26:25.277 回答