2011-05-05 125 views
2

你好我想OrderByDescending()上查询,但不是:LINQ OrderByDescending传递一个字符串值

results = results.OrderByDescending(o => o.Surname); 

我希望用:

results = results.OrderByDescending(o => "Surname"); 

引号中的值会在中传递一个参数。

我在看反射,但不确定。

回答

2

我使用这样的

results = results.OrderByDescending(o => o.GetType().GetProperty("Surname").GetValue(o, null).ToString())