How to map a composite id to white nhibernate using an interface?

I am trying to disable mappings .hbmfor smooth mappings and the problem with displaying compound identifiers and using interfaces

The class is as follows:

public class ClassWithCompositeId {
  public virtual IKeyOne KeyOne { get; set; }
  public virtual IKeyTwo KeyTwo { get; set; }
}

our hbm mapping is as follows:

<hibernate-mapping ...>
   <class name="ClassWithCompositeId" table="t_classwithcompositeid">
      <composite-id>      
         <key-many-to-one name="KeyOne" column="colkeyone" class="company.namespace.boSkillBase, BL_Stammdaten" />
         <key-many-to-one name="KeyTwo" column="colkeytwo" class="boQualifikation" />         
      </composite-id>
</hibernate-mapping>

Please note that we got the interfaces in the class! No. I am trying to match this with Fluent nhibernate.

Map {
   public ClassWithCompositeIdMap() {
         CompositeId()
            .KeyReference(x => x.KeyOne, "colkeyone")
            .KeyReference(x => x.KeyTwo, "colkeytwo");
          ...
   }
}

But now, Fluent generates a mapping as follows:

...
 <composite-id mapped="false" unsaved-value="undefined">
      <key-many-to-one name="KeyOne" class="company.namespace.IKeyOne, Interfaces, Version=0.1.4.3379, Culture=neutral, PublicKeyToken=null">
        <column name="colkeyone" />
      </key-many-to-one>
      <key-many-to-one name="KeyTwo" class="company.namespace.IKeyTwo, Interfaces, Version=0.1.4.3379, Culture=neutral, PublicKeyToken=null">
        <column name="colkeytwo" />
      </key-many-to-one>
    </composite-id>
...

The Class attribute now indicates the interface is not an implementation of this interface, which leads to an error.

How can I tell Fluent nHibernate to use another class as an attribute value?

+3
2

! . nHibernate. ​​ dev Paul Batum.

:

   Map {
      public ClassWithCompositeIdMap() {
            CompositeId()
               .KeyReference(x => x.KeyOne, k =>
                   k.Type<KeyOneImplementation>(), "colkeyone")
               .KeyReference(x => x.KeyTwo, k =>
                   k.Type<KeyTwoImplementation>(), "colkeytwo");
             ...
      }
   }

http://github.com/paulbatum/fluent-nhibernate/tree/dev

: http://support.fluentnhibernate.org/discussions/help/349-how-to-map-a-composite-id-when-using-interfaces-or-how-to-change-the-class-attribute-in-the-key-many-to-one-tag

+2

NhGen SourceForge. Fluent .. , , , .

, ,

 CompositeId()
            .ComponentCompositeIdentifier(x => x.Key, "Namespace.Key, Assembly")
            .KeyProperty(x => x.Key.Id1, "Id1")
            .KeyProperty(x => x.Key.Id2, "Id2")
            .KeyProperty(x => x.Key.Id3, "Id3");
+3

Source: https://habr.com/ru/post/1770919/


All Articles