Question

Need help in converting this linq query to Expression Tree

Dim query = (From _row In table.Rows
                 Group _row By vGroup = _row("VENDOR")
                 Into VendorGroup = Group
            Select New With {
                Key vGroup,
                    .PI = VendorGroup.Sum(Function(r) r("PI")),
                    .ST = VendorGroup.Sum(Function(r) r("ST")),
                    .IS = VendorGroup.Sum(Function(r) r("IS")),
                    .RR = VendorGroup.Sum(Function(r) r("RR"))
           }).ToList
Was it helpful?

Solution

You can try converting to IQueryable then pulling out the Expression property:

Dim expression = (From _row In table.Rows
             Group _row By vGroup = _row("VENDOR")
             Into VendorGroup = Group
        Select New With {
            Key vGroup,
                .PI = VendorGroup.Sum(Function(r) r("PI")),
                .ST = VendorGroup.Sum(Function(r) r("ST")),
                .IS = VendorGroup.Sum(Function(r) r("IS")),
                .RR = VendorGroup.Sum(Function(r) r("RR"))
       }).AsQueryable()
         .Expression

but the expression you get back may vary depending on the query provider you're using.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top