views:

37

answers:

0

I have an Entity class which has a Dictionary of fields called Data. Now I want to sort Entities by a field in Data. I tried somethings like -

Entities.OrderBy(e => e.Data["UserId"]) and (e => e.Data.UserId)

but both of these fail to create the right Criteria in NHibernate which should be something like {Data.UserId asc}. What is the correct Linq expression for this? Also are there any limitations in the NHibernate Linq visitor I should be aware of?

Thanks in advance.

Updated

I was able to verify the Linq expression for using fields in a dictionary as e.Data["UserId"] as this seemed to work perfectly when I used LINQ to Objects.

However this same expression does not generate the correct NHibernate criteria and errors out finally with a NullReferenceException for propertyName at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetEntityName(ICriteria subcriteria, String propertyName) in CriteriaQueryTranslator.cs: line 541.

On debugging through NHibernate code, I figured that NHibernate.Linq.Visitors.MemberNameVisitor.GetMemberName(ICriteria rootCriteria, Expression expr) returns a null string in place of the field name after visiting expr using its visitor. This seems to be the cause of grief.