Using Nihibernate with system dynamic linq for Query

dynamic-linq mysql nhibernate

Question

I am trying to use system.dynamic.linq to create dynamic sorting.

this, is the query that I use:

var query = dalSession.Query<T>().AsQueryable();
var res = (from x in query orderby "x.FirstName" select x)

this is the mysql output:

select
     affiliate0_.id as id0_,
     affiliate0_.first_name as first6_0_,
from affiliate affiliate0_ order by 'x.FirstName' //FirstName as well

So you can see that the output went to the mysql query is the direct string, and not its reflection, ('x.FirstName') or ('FirstName').
This has no meaning in mysql context, it looks like I need order by affiliate0_.first_name.
Is there anyway to provide the Nhibernate the member itself? So the compiled query will be done normally?

1
1
11/7/2012 8:30:08 AM

Popular Answer

var param = Expression.Parameter("x");
var prop = Expression.Property(param, "FirstName");
var lambda = Expression.Lambda<Func<User, string>>(prop, param);
query.Orderby(lambda);
0
3/13/2013 9:28:51 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow