NHibernate ComponentAsId()实际上没有设置Id属性

NHibernate ComponentAsId()实际上没有设置Id属性,nhibernate,nhibernate-mapping,Nhibernate,Nhibernate Mapping,我正在尝试使用编码映射设置NHibernate(3.2.0.4000),但我无法使ComponentAsId正常工作 我有一个无法更改的数据库架构,其中主键由字符串和日期组成,因此我需要使用组件作为Id: i、 e 数据库模式 班级 映射 var-mapper=new ConventionModelMapper(); 类(map=>map.ComponentAsId(id=>id.Identity,cid=> { 属性(x=>x.Id,x=>x.Length(20)); cid.Property

我正在尝试使用编码映射设置NHibernate(3.2.0.4000),但我无法使ComponentAsId正常工作

我有一个无法更改的数据库架构,其中主键由字符串和日期组成,因此我需要使用组件作为Id:

i、 e

数据库模式 班级 映射
var-mapper=new ConventionModelMapper();
类(map=>map.ComponentAsId(id=>id.Identity,cid=>
{
属性(x=>x.Id,x=>x.Length(20));
cid.Property(x=>x.EffectiveDate);
}));
但这不起作用,因为MyClass上的Identity属性为null

作为XML的映射如下所示:

<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:nhibernate-mapping-2.2">
    <class name="Test.MyClass, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <composite-id class="EffectiveDateId, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
            <key-property name="Id" type="AnsiString" length="20" />
            <key-property name="EffectiveDate" />
        </composite-id>
        <property name="Property1" />
    </class>
</hibernate-mapping>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:nhibernate-mapping-2.2">
    <class name="Test.MyClass, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <composite-id name="Identity" class="EffectiveDateId, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
            <key-property name="Id" type="AnsiString" length="20" />
            <key-property name="EffectiveDate" />
        </composite-id>
        <property name="Property1" />
    </class>
</hibernate-mapping>

但是,如果手动将XML更改为包含name=“Identity”如下所示:

<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:nhibernate-mapping-2.2">
    <class name="Test.MyClass, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <composite-id class="EffectiveDateId, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
            <key-property name="Id" type="AnsiString" length="20" />
            <key-property name="EffectiveDate" />
        </composite-id>
        <property name="Property1" />
    </class>
</hibernate-mapping>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:nhibernate-mapping-2.2">
    <class name="Test.MyClass, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <composite-id name="Identity" class="EffectiveDateId, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
            <key-property name="Id" type="AnsiString" length="20" />
            <key-property name="EffectiveDate" />
        </composite-id>
        <property name="Property1" />
    </class>
</hibernate-mapping>

它起作用了

我尝试通过添加(除了ComponentAsId映射之外)来设置id

mapper.Class(map=>map.Id(Id=>Id.Identity));
但这只会生成一个NHibernate.MappingException

Test.MyClass id的映射不明确。已定义id属性和生成器,您正试图将属性“Identity”的组件Test.EffectiveDateId映射为Test.MyClass的id

使用调试器,我可以看到对于代码映射配置,ClassMapping.IdentifierProperty为null,而在XML配置中,它被设置为NHibernate.Mapping.Property实例

那么,ComponentAsId()的实现中是否存在未设置IdentifierProperty的bug,或者我是否做错了

问候,,
伊蒙

对我来说,它确实像一只虫子。我很确定这也是一个bug,所以我记录了一个错误,这个错误现在已经在源代码的主分支中修复了。
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:nhibernate-mapping-2.2">
    <class name="Test.MyClass, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <composite-id name="Identity" class="EffectiveDateId, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
            <key-property name="Id" type="AnsiString" length="20" />
            <key-property name="EffectiveDate" />
        </composite-id>
        <property name="Property1" />
    </class>
</hibernate-mapping>
mapper.Class<MyClass>(map => map.Id(id => id.Identity));