开发者

NHibernate Multiple Criteria Difficulties

开发者 https://www.devze.com 2022-12-22 15:28 出处:网络
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, o

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

精彩评论

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

关注公众号