你好我想OrderByDescending()
上查询,但不是:LINQ OrderByDescending传递一个字符串值
results = results.OrderByDescending(o => o.Surname);
我希望用:
results = results.OrderByDescending(o => "Surname");
引号中的值会在中传递一个参数。
我在看反射,但不确定。
你好我想OrderByDescending()
上查询,但不是:LINQ OrderByDescending传递一个字符串值
results = results.OrderByDescending(o => o.Surname);
我希望用:
results = results.OrderByDescending(o => "Surname");
引号中的值会在中传递一个参数。
我在看反射,但不确定。
看一看LINQ动态查询库:http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
这将允许您使用results.OrderByDescending("Surname");
我使用这样的
results = results.OrderByDescending(o => o.GetType().GetProperty("Surname").GetValue(o, null).ToString())
或者这里检查C#4版:HTTP: //weblogs.asp.net/davidfowler/archive/2010/08/19/dynamic-linq-part-2-evolution.aspx – 2011-05-05 15:43:31
这很有魅力。谢谢 – markpcasey 2011-05-05 15:53:53