C# LINQ OrderByDescending传递字符串值
您好,我正在尝试对查询执行C# LINQ OrderByDescending传递字符串值,c#,linq,linq-to-entities,iqueryable,C#,Linq,Linq To Entities,Iqueryable,您好,我正在尝试对查询执行OrderByDescending(),但不是: results = results.OrderByDescending(o => o.Surname); 我希望使用: results = results.OrderByDescending(o => "Surname"); 引号中的值将在参数中传递 我看着倒影,但不确定 看看LINQ动态查询库: 这将允许您使用results.OrderByDescending(“姓氏”)我使用这样的东西 res
OrderByDescending()
,但不是:
results = results.OrderByDescending(o => o.Surname);
我希望使用:
results = results.OrderByDescending(o => "Surname");
引号中的值将在参数中传递
我看着倒影,但不确定 看看LINQ动态查询库:
这将允许您使用
results.OrderByDescending(“姓氏”)代码>我使用这样的东西
results = results.OrderByDescending(o => o.GetType().GetProperty("Surname").GetValue(o, null).ToString())
或者在此处查看C#4版本: