开发者

NHibernate Multiple Criteria Difficulties

I'm having difficulties with multiple joins in the NHibernate Criteria search. Say I had a pet table, and I wanted to return all pets where the pet category was Dog, and the owner gender was female, ordered by the pet birthday. I've tried a bunch of permutations for how I can get this but haven't been able to figure it out. My latest iteration is as follows:

var recentPets = session.CreateCriteria(typeof(Pet))
            .AddOrder(Order.Desc("PetBirthday"))
            .CreateCriteria("PetType", "pt", JoinType.InnerJoin)
          开发者_开发问答  .CreateCriteria("PetOwnerId", "po", JoinType.InnerJoin)
            .Add(Expression.Eq("pt.PetTypeName", petType))
            .Add(Expression.Eq("po.PersonGender", gender))
            .List<Pet>();

Thanks so much for the help!


Is there a reason you are not using the Hibernate/Java persistence query language to perform the query?

select p from Pet p
join p.owner o
where o.gender = :gender
and p.type.name = :petType
order by p.birthday
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜