如何使用接口映射复合id与流利的nhibernate? [英] How to map composite-id with fluent nhibernate using an interface?

查看:218
本文介绍了如何使用接口映射复合id与流利的nhibernate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将 .hbm 映射为流畅的映射,并且在复合标识的映射和接口的使用方面存在问题。 b
$ b

类看起来如下:

pre $ public class ClassWithCompositeId {
public virtual IKeyOne KeyOne {get;组; }
public virtual IKeyTwo KeyTwo {get;组; }
}

我们的hbm映射如下所示:

 < hibernate-mapping ...> 
< class name =ClassWithCompositeIdtable =t_classwithcompositeid>
< composite-id>
< / composite-id>
< / hibernate-mapping>

请注意,我们在Class中获得了接口!不,我试图映射这与流利nhibernate。

 地图{
public ClassWithCompositeIdMap(){$ b $ (x => x.KeyOne,colkeyone)
.KeyReference(x => x.KeyTwo,colkeytwo);
...
}
}

映射如下:

  ... 
< column name =colkeyone/>
< / key-many-to-one>
< column name =colkeytwo/>
< / key-many-to-one>
< / composite-id>
...

Class属性现在指向Interface而不是实现



如何告诉Fluent nHibernate使用另一个类作为属性值?

解决方案

坦克!但是我已经找到了答案。事实上,我发现流利的nHibernate缺少一个功能。这个功能已经被Paul Batum添加到了开发分支中。



你可以像这样使用它:

 public ClassWithCompositeIdMap(){
CompositeId()
.KeyReference(x => x.KeyOne,k => $ b $ (),colkeytwo)(b)类型< KeyOneImplementation>(),colkeyone)
.KeyReference(x => x.KeyTwo,k =>
k.Type< KeyTwoImplementation> ;
...
}
}

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



你可以在这里看到原来的对话: http://support.fluentnhibernate。组织/讨论/求助/ 349-如何到MAP-A-复合-ID-时,使用接口或 - 如何对变化的类属性,在最关键的许多-TO-一个标签


I'm trying to switch out .hbm mappings to fluent mappings and have a problem with the mapping of composite-ids and the usage of Interfaces

the Class looks as follows:

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

our hbm mapping looks like this:

<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 interfaces in the Class! No I'm trying to map this with Fluent nhibernate.

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

But now Fluent generates the 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 points now to the Interface not to the implementation of this interface which results in an error.

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

解决方案

Tanks! But I've found the answer on my on. In fact i found a missing feature in fluent nHibernate. The feature has already been added to the dev branch by Paul Batum.

You would use it like so:

   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

You can see the original Conversation here: 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

这篇关于如何使用接口映射复合id与流利的nhibernate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆