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

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top