3

動的 linq を使用して、列を動的に選択しています。私はこれについて明確にする必要があります。どうすればこれを行うことができますか?

var qry = tbl.AsEnumerable().AsQueryable()
             .Select("new(it[\"" + this.UniqueName + "\"]
             .ToString() as " + this.UniqueName + ")");

ありがとう。

4

1 に答える 1

4

使用する代わりに

as " + this.UniqueName + "

行う

as someFixedColumnName

Distinct()通常のLinqを使用して、その句を実行します。


または、次の拡張メソッドを試すこともできます。

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));
}
于 2011-04-13T20:47:17.723 に答える