0

在流利的 nhibernate 中,我可以设置对实现如下接口的具体类的引用:

class Address : IAddress {
...
}

class Person {
    public virtual IAddress Address {get;set;}
}

...

class PersonMap : ClassMap<Person> {
    public PersonMap() {
        References<Address>(x => x.Address).Column("AddressId");
        ...
    }
 }

有没有办法在代码映射中只使用 nhibernate 来做到这一点?

谢谢!

4

1 回答 1

2

你的意思是通过冗长的映射,对吧?这样做是这样的:

using NHibernate;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

public class PersonMapping : ClassMapping<Person>
{
    public PersonMapping()
    {
        ...

        ManyToOne(x => x.Address, map =>
                                   {
                                       map.Column("AddressId");                                           
                                       map.Class(typeof(Address));
                                   }
            );

       ...
    }
}
于 2013-07-22T13:23:37.607 回答