0
我正在嘗試生成一個表達式樹,最終調用Enumerable類型的一系列GroupBy方法。需要幫助創建Linq.Expression到Enumerable.GroupBy
以簡單的形式,我試圖這樣的事情:
IEnumerable<Data> list = new List<Data>{new Data{Name = "A", Age=10},
new Data{Name = "A", Age=12},
new Data{Name = "B", Age=20},
new Data{Name="C", Age=15}};
Expression data = Expression.Parameter(typeof(IEnumerable<Data>), "data");
Expression arg = Expression.Parameter(typeof(Data), "arg");
Expression nameProperty = Expression.PropertyOrField(arg, "Name");
Expression group = Expression.Call(typeof(Enumerable), "GroupBy", new Type[] { typeof(Data), typeof(string) }, data, nameProperty);
呼叫在年底Expression.Call拋出「沒有方法上鍵入'的GroupBy‘System.Linq.Enumerable’與兼容提供的參數。「
我正在做類似的事情,以類似的方式與Enumerable.OrderBy
成功和難住。
任何幫助表示讚賞。
工作。謝謝 – dkackman 2009-10-30 16:20:06