I could use some help with expression conversion.
I have a method on a class which looks like the following:
protected IQueryOver<TEntity, TEntity> OrderQuery<TOrderBy>(
Expression<Func<TEntity, TOrderBy>> orderBy)
{
return session.QueryOver<TEntity>().OrderBy(orderBy).Asc;
}
This is a generic query for a repository class. I want to keep things generic so I specified the TOrderBy parameter so that the type of the property doesn’t matter. However, this implementation example is using NHibernate and I’m trying to do the following:
var query = session.QueryOver<TEntity>().OrderBy(orderBy).Asc;
However, ther OrderBy method takes a parameter of Expression> and therefore I get a compile error as there is no guarantee that TOrderBy would be an object.
Is there a way of doing this conversion or should I just stick with using object rather than TOrderBy? If I stick with object, do I not lose the ability to order by ValueTypes (e.g. DateTime)?
Thanks for any help/suggestions.
EDIT: I should mention, I have kept this generic as I will be writing implementations for nhibernate and entity framework. There isnt an issue with this in EF as it uses the normal Linq OrderBy method. It is just in the Nhibernate implementation I’m having this problem
If you are using LINQ with EF, why not use LINQ with NHibernate too instead of QueryOver?