我正在使用动态 linq 并动态选择一列。我需要对此做一个明确的。我怎么能这样做?
var qry = tbl.AsEnumerable().AsQueryable()
.Select("new(it[\"" + this.UniqueName + "\"]
.ToString() as " + this.UniqueName + ")");
谢谢。
我正在使用动态 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));
}