Dynamic Linq GroupBy

我的未来我决定 提交于 2019-12-11 06:04:48

问题


I followed the bellow steps to solve a similar problem as described however i dont seem to be able to get the solution to work System.LINQ.Dynamic: Select(" new (...)") into a List<T> (or any other enumerable collection of <T>)

I have even created a project so that it is the exact same as shown.

I get an error saying that "No property or field 'Fund' exists in type 'DataRow'"

I tried to get around this problem with:

IQueryable<Result> res = table1.AsEnumerable().AsQueryable()
                              .GroupBy("it[\"Fund\"]", "it")
                              .Select<Result>("new (Key as Group, Sum(Convert.ToDouble(it[\"Value\"].ToString())) as  TotalValue)");

but while this gets me past the above error i now have a problem getting the sum as the error states

Argument types do not match

Not sure where to go from here Thanks


回答1:


IQueryable<Result> res = table1.AsEnumerable().AsQueryable()
                               .GroupBy("it[\"Fund\"]", "it")
                               .Select<Result>("new (Key.ToString() as Group, Sum(Convert.ToDouble(it[\"Value\"].ToString())) as TotalValue)");

That works!! - needed to do a ToString() on the key



来源:https://stackoverflow.com/questions/3469694/dynamic-linq-groupby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!