2
我使用Fluent NHibernate和每个子类的继承映射。 我想引用特定对象的列表,但我无法弄清楚,如何将结果复原到某个特定类的对象。 流利的NHibernate继承映射问题
class PetMap : ClassMap<Pet>
{
public PetMap()
{
Id(c => c.ID).GeneratedBy.Identity();
}
}
class DogMap : ClassMap<Dog>
{
public DogMap()
{
Mac(c => c.DogSpecificProperty);
}
}
class CatMap : SubclassMap<Cat>
{
public CatMap()
{
Mac(c => c.CatSpecificProperty);
}
}
class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(c => c.ID).GeneratedBy.Identity();
//this works fine
HasMany(c => c.Pets);
//this dosen't work, because the result contains dogs and cats
//how can I tell NHibernate to only fetch dogs or cats?
HasMany<Pet>(c => c.Cats);
HasMany<Pet>(c => c.Dogs);
}
}
class Pet
{
int ID;
}
class Dog : Pet
{
object DogSpecificProperty;
}
class Cat : Pet
{
object CatSpecificProperty;
}
class Person
{
int ID;
IList<Pet> Pets;
IList<Dog> Dogs;
IList<Cat> Cats;
}
任何人都可以帮助我吗?请原谅我可怜的英语。
HasMany(c => c.Cats)
这看起来有点痘痘愚蠢,但我认为这是正确的,因为宠物表有Person表的参考。我从其他堆栈溢出问题中得到这个解决方案。 在我看来,HasMany@trichterwolke如果你说猫和狗类实际上来自数据库中的宠物表,那么我认为你会说在CatMap和DogMap中,而不是在PersonMap中。我相信这就是我以前在使用FNH时所做的。 – Joseph 2009-11-12 18:29:43