This doesn't do quite what you want (i.e. count(distinct(field)) ) but if you want to be able to call Distinct on a dynamic linq iqueryable, add the following extension method:
public static IQueryable Distinct(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));
}
Kristofer - Huagati Systems Co., Ltd. - Cool tools for Linq-to-SQL and Entity Framework:
www.huagati.com/dbmltools (VS designer add-in),
www.huagati.com/L2SProfiler (query profiler for L2S)