如何在 NHibernate 中获取键属性的映射?

发布于 2024-09-16 17:11:25 字数 794 浏览 2 评论 0原文

我正在尝试使用以下几行在运行时加载 POCO 类的 nhibernate 映射:

var persistentClass = NHibernateHelper.Configuration.GetClassMapping( type );
var property = persistentClass.GetProperty( propertyName );

它工作正常,但它在具有以下映射的类上的属性 GroupId 上失败:

<class name="GroupPartnerInterest" table="[GROUP_PARTNER_INTERESTS]">
  <composite-id >
    <key-property name="GroupId" column="PAR_ID" />

If type == typeof(GroupPartnerInterest) persistentClass.GetProperty( "GroupId" ) 失败并出现 MappingException:

找不到属性:实体上的 GroupId 集团合作伙伴兴趣”

我可以在调试器中看到来自 composite-idkey-properties 没有出现在 persistClass.properties 中。

有没有办法获取此键属性的映射?

先感谢您。

I'm trying to load nhibernate mapping for POCO classes at runtime with following lines:

var persistentClass = NHibernateHelper.Configuration.GetClassMapping( type );
var property = persistentClass.GetProperty( propertyName );

It works fine except it fails on property GroupId on a class with following mapping:

<class name="GroupPartnerInterest" table="[GROUP_PARTNER_INTERESTS]">
  <composite-id >
    <key-property name="GroupId" column="PAR_ID" />

If type == typeof(GroupPartnerInterest) persistentClass.GetProperty( "GroupId" ) fails with MappingException:

property not found: GroupId on entity
GroupPartnerInterest"

I can see in debugger that key-properties from composite-id do not appear in persistentClass.properties.

Is there a way to get mapping for this key-property?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咆哮 2024-09-23 17:11:25

普通属性可以通过persistentClass.PropertyClosureIterator 进行迭代(即包括来自基类的属性)。

关键属性位于 ( ( Component )( permanentClass.Identifier ) ).PropertyIterator 中。

因此,通过这段代码,我可以搜索关键属性和普通属性:

var propserties = persistentClass.PropertyClosureIterator;
if ( persistentClass.Identifier is Component )
{
    properties = ( ( Component )( persistentClass.Identifier ) ).PropertyIterator
                    .Union( properties );
}

Property property
    = (
        from it in properties
        where it.Name == propertyName
        select it
      ).FirstOrDefault();

The ordinary properties can be iterated through persistentClass.PropertyClosureIterator (that is including properties from base classes).

The key properties are in ( ( Component )( persistentClass.Identifier ) ).PropertyIterator.

So with this piece of code I'm able to search both key properties and ordinary properties:

var propserties = persistentClass.PropertyClosureIterator;
if ( persistentClass.Identifier is Component )
{
    properties = ( ( Component )( persistentClass.Identifier ) ).PropertyIterator
                    .Union( properties );
}

Property property
    = (
        from it in properties
        where it.Name == propertyName
        select it
      ).FirstOrDefault();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文