2

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

Community
  • 1
  • 1
Ronan
  • 41
  • 1
  • 4

1 Answers1

2
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

Peter Majeed
  • 5,304
  • 2
  • 32
  • 57
Ronan
  • 41
  • 1
  • 4