【发布时间】:2012-09-03 06:38:49
【问题描述】:
我正在尝试利用 James McCormack 的指南来使用带有 Dynamic Linq 的自定义 IComparer。 - 见http://zootfroot.blogspot.co.uk/2009/10/dynamic-linq-orderby.html?showComment=1347276236930#c11348033278810583
我使用查询来拉回一个可枚举的字符串值:
.Select("fieldname").Distinct()
那就试试用
.OrderBy(item=>item.GetReflectedPropertyValue("fieldname"),new myComparer())
GetReflectedPropertyValue 是 James 定义为的辅助方法
public static string GetReflectedPropertyValue(this object subject, string field)
{
object reflectedValue = subject.GetType().GetProperty(field).GetValue(subject, null);
return reflectedValue != null ? reflectedValue.ToString() : "";
}
但是得到错误“'System.Collections.Generic.IEnumerable'不包含'OrderBy'的定义和最佳扩展方法重载'System.Linq.Dynamic.DynamicQueryable.OrderBy(System.Linq.IQueryable, string , params object[])' 有一些无效参数"
有什么想法吗?我对此很陌生,只是想在我有时间真正经历并正确学习它之前让一些东西发挥作用。
【问题讨论】:
标签: c# linq dynamic sql-order-by