I am trying to order a dynamic NHibernate 3.0 Linq query based on the name of a column stored in a string variable.
string columnName = "column1";
var query = from n in Session.Query<Document>()
where n.DocumentNumber == documentNumber
select n;
The keyword orderbytakes a string (or variable), but when I do the following:
var query = from n in Session.Query<Document>()
where n.DocumentNumber == documentNumber
orderby columnName
select n;
I get this exception:
request failed
select TOP (@p0)
accumulate0_.Id as Id9_,
accumulate0_.DocumentNumber as Documen10_9_
from dbo.Documents accumulate0_
where
accumulate0_.DocumentNumber=@p1
order by @p2 desc
The SELECT element identified by ORDER BY number 1 contains the variable as part of the expression identifying the position of the column. Variables are only allowed when ordering an expression that refers to a column name.
LINQ Dynamic Query Library, .OrderBy, , , . NHibernate 3.0.
, ORDER BY SQL- , NHibernate.
NHibernate, , NHibernate Linq, .