我正在使用动态linq并动态选择一列。我需要对此做一个独特的描述。我该怎么办?
var qry = tbl.AsEnumerable().AsQueryable()
.Select("new(it[\"" + this.UniqueName + "\"]
.ToString() as " + this.UniqueName + ")");
谢谢。
而不是使用
as " + this.UniqueName + "
做
as someFixedColumnName
并使用普通的Linq在其上运行您的Distinct()
子句。
另外,您可以尝试以下扩展方法:
public static IQueryable DynamicDistinct(this IQueryable source)
{
if (source == null) throw new ArgumentNullException("source");
return source.Provider.CreateQuery(
Expression.Call(
typeof(Queryable), "Distinct",
new Type[] { source.ElementType },
source.Expression));
}