【问题标题】:How to use an Interface as part of a CompositeID in fluent Nhibernate如何在流利的 Nhibernate 中使用接口作为 CompositeID 的一部分
【发布时间】:2012-01-05 23:32:31
【问题描述】:

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

我想要做的是:

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();
}

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

我读到了:

Fluent NHibernate, working with interfaces

Programming to interfaces while mapping with Fluent NHibernate

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

【问题讨论】:

    标签: nhibernate fluent-nhibernate nhibernate-mapping composite-id


    【解决方案1】:

    这可能有效

    .KeyReference(x => x.myFoo, attr => attr.Column("fooID").EntityName("bar1"))
    

    【讨论】:

    • 不幸的是,我使用的是旧版本的 fluent,我没有任何与该签名匹配的功能。
    • 那么您必须进行反思或扩展您自己的 FNH 版本。如果需要,我可以发布反射代码。
    猜你喜欢
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多