简体   繁体   English

如何在流畅的Nhibernate中将接口用作CompositeID的一部分

[英]How to use an Interface as part of a CompositeID in fluent Nhibernate

I'm having trouble figuring out how to map an interface while using a composite key. 我在弄清楚如何在使用复合键的同时映射接口时遇到了麻烦。

What I'm trying to do is this: 我想做的是这样的:

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

The References works without issue, but I can't get the KeyReference to work, and there doesn't seem to be any ".Class" I can use like I can with References. 引用可以正常工作,但是我无法使KeyReference正常工作,并且似乎没有可以像引用一样使用的“ .Class”。

I read: 我读:

Fluent NHibernate, working with interfaces 流利的NHibernate,使用接口

Programming to interfaces while mapping with Fluent NHibernate 使用Fluent NHibernate映射时对接口进行编程

and that let me fix the References issue, but I haven't found a work around for the KeyReference. 这样就可以解决“引用”问题,但是我还没有找到解决KeyReference的方法。 Is there something obvious I'm missing, cause I've been googling around for awhile, and so far haven't been able to find anything. 有什么明显的我想念的东西吗,因为我已经搜索了一段时间了,到目前为止还找不到任何东西。

这也许有效

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM