How do I order by a variable column name in entity framework?

  • Thread starter Thread starter Ilyas
  • Start date Start date
I

Ilyas

Hi all

I have an EDM for the northwind database. I want a variable, which
contains the name of the column that I am ordering by

If I do:

string orderColumnName = "UnitPrice";
NorthwindDefaultEntities ne = new NorthwindDefaultEntities
();
var items2 = ne.Products.OrderBy(orderColumnName);
Console.WriteLine(ne.Products.ToTraceString());
Assert.AreEqual(33, items2.First().ProductID);


I get the error:

System.Data.EntitySqlException : 'UnitPrice' could not be resolved in
the current scope or context. Make sure that all referenced variables
are in scope, that required schemas are loaded, and that namespaces
are referenced correctly., near simple identifier, line 6, column 1.

How can I resolve this?
 
Back
Top