Reputation: 4450
I would like to ask on how you do ordering on an object with 2 properties that are basically joined from 2 entities.
Lets say "ClassA" has a property named ClassB and ClassC which are also classes themselves. ClassB has a property named Name and ClassC also has a property named Name. Now, since ClassB and ClassC are both properties of ClassA, how can i order a list of ClassAs using the Name properties of ClassB and ClassC. Below is the sample NHibernate criteria code in C#:
ICriteria criteria = m_Session.CreateCriteria<ClassA>()
.AddOrder(Order.Asc("ClassB.Name"))
.AddOrder(Order.Asc("ClassC.Name"));
But the above code throws an error saying that "could not resolve property: ClassB.Name of: ClassA". Any help would be appreciated. Thanks a lot.
Upvotes: 2
Views: 935
Reputation: 25956
You will need to alias the 2 associations (ClassB & ClassB) so that you can order by them.
ICriteria criteria = m_Session.CreateCriteria<ClassA>()
.CreateAlias("ClassB", "b")
.CreateAlias("ClassC", "c")
.AddOrder(Order.Asc("b.Name"))
.AddOrder(Order.Asc("c.Name"));
Upvotes: 4