0

我在使用复合键时无法弄清楚如何映射接口。

我想要做的是:

interface Ifoo
{
  int someInt {get;}
  int id {get;}
}

class bar1: Ifoo
{
  int someInt {get; protected internal set;}
  int id {get; protected internal set;}
}

class bar2: Ifoo
{
  int someInt {get; protected internal set;}
  int id {get; protected internal set;}
}

class someOtherClass
{
  Ifoo myFoo {get; protected internal set;}
  int id {get; protected internal set;}
}

public class someOtherClassMap: ClassMap<someOtherClass>
{
  CompositeId()
    .KeyReference(x => x.myFoo, "fooID")
    .KeyProperty(x => x.id, "id");

  References(x => x.myFoo)
    .Class(typeof (foo1))
    .Class(typeof (foo2))
    .Column("fooID")
    .Not.Insert()
    .Not.Update();
}

References 没有问题,但我无法让 KeyReference 工作,而且似乎没有任何“.Class”我可以像使用 References 一样使用。

我读:

流利的 NHibernate,使用接口

使用 Fluent NHibernate 映射时对接口进行编程

这让我解决了引用问题,但我还没有找到解决 KeyReference 的方法。有什么明显的我失踪了,因为我已经在谷歌上搜索了一段时间,到目前为止还没有找到任何东西。

4

1 回答 1

0

这可能有效

.KeyReference(x => x.myFoo, attr => attr.Column("fooID").EntityName("bar1"))
于 2012-01-06T15:14:41.253 回答