添加对鉴别器(类类型)的限制,以选择fluent nhibernate中类的子集

添加对鉴别器(类类型)的限制,以选择fluent nhibernate中类的子集,nhibernate,fluent-nhibernate,queryover,discriminator,Nhibernate,Fluent Nhibernate,Queryover,Discriminator,我正在使用fluent nhibernate和子类的鉴别器。(非常类似于) 例如,假设我有Cat、Dog和Racoon类,它们扩展了抽象类Animal 我希望能够同时选择猫和狗,但不选择浣熊。所以 return _db.CreateCriteria<Cat>.List<Cat>(); 它是变体,但总是导致错误 请问,有没有办法指定查询对象中需要哪些子类 再翻一些,我发现你能做到 但我仍然无法将其转换为ICriteria/Query对象。未经测试,但类似的东西应该可以工

我正在使用fluent nhibernate和子类的鉴别器。(非常类似于)

例如,假设我有Cat、Dog和Racoon类,它们扩展了抽象类Animal

我希望能够同时选择猫和狗,但不选择浣熊。所以

return _db.CreateCriteria<Cat>.List<Cat>();
它是变体,但总是导致错误

请问,有没有办法指定查询对象中需要哪些子类


再翻一些,我发现你能做到


但我仍然无法将其转换为ICriteria/Query对象。

未经测试,但类似的东西应该可以工作

this.Where(Restrictions.Disjunction()
    .Add(Restrictions.Eq("class", typeof(Cat)))
    .Add(Restrictions.Eq("class", typeof(Dog))));
参见

Animal-Animal=null;
询问者(()=>动物)
.Where(()=>animal.GetType().IsIn(新[]{Animals.Cat.ToString(),Animals.Dog.ToString()}))
哪里是您的鉴别器枚举

 from Eg.Cat cat where cat.class = Eg.DomesticCat
this.Where(Restrictions.Disjunction()
    .Add(Restrictions.Eq("class", typeof(Cat)))
    .Add(Restrictions.Eq("class", typeof(Dog))));
Animal animal = null;

QueryOver<Animal>(() => animal)
 .Where(() => animal.GetType().IsIn(new[] { Animals.Cat.ToString(), Animals.Dog.ToString() }))