简体   繁体   中英

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.

I read:

Fluent NHibernate, working with interfaces

Programming to interfaces while mapping with Fluent NHibernate

and that let me fix the References issue, but I haven't found a work around for the 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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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