VB.Net Linq To SQL Sub Select

时间:2009-10-12 13:51:33

标签: vb.net linq-to-sql

我有以下查询对某些记录进行分组,然后过滤分组记录的计数为1。

我想获取返回的结果并执行另一个查询以从JobcodesWorkingRollup表中检索整个记录,其中ParentNode列等于此查询的结果:

        Dim query = From r In context.GetTable(Of JobcodesWorkingRollup)() _
        Group r By r.ParentNode Into g = Group _
        Where g.Count = 1 _
        Select New With {.cnt = g.Count, .nm = g.FirstOrDefault.ParentNode}

谢谢!

1 个答案:

答案 0 :(得分:0)

我想我拥有它......有更好的方法吗?

        Dim query = From r In context.GetTable(Of JobcodesWorkingRollup)() _
        Group r By r.ParentNode Into g = Group _
        Where g.Count = 1 _
        From rr In context.GetTable(Of JobcodesWorkingRollup)() _
        Where rr.ParentNode = g.FirstOrDefault.ParentNode _
        Select New With {.record = rr}