将Linq转换为表达式树

时间:2013-12-05 21:14:44

标签: vb.net linq linq-to-objects

需要帮助将此linq查询转换为表达式树

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

1 个答案:

答案 0 :(得分:2)

您可以尝试转换为IQueryable,然后取出Expression媒体资源:

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

但您获得的表达式可能会因您使用的查询提供程序而异。