0

我有以下 LINQ 查询:

From metasect In DirectCast(Form.ChildDocBox.Tag, META_DOCUMENT).META_SECTIONS
From metaset In metasect.META_SETS
From metacell In metaset.META_CELLS
From lookup In metacell.CHILD_META_CELL_CELLS_LOOKUPS
Where lookup.PARENT_META_CELL_META_CELL.META_SET.META_SECTION.META_DOCUMENT.META_DOC_ID = docToDelete.META_DOC_ID
Select metasect.META_SECT_NAME + " gets from " + lookup.PARENT_META_CELL_META_CELL.META_SET.META_SECTION.META_SECT_NAME Distinct

Select指令选择一个可以重复的表达式,因为在同一对父子元节有多个查找,就是我添加 Distinct子句的原因。

现在,我想计算每个父母/子女夫妇有多少查找。

就像是

SELECT metasect.META_SECT_NAME + " gets from " + lookup.PARENT_META_CELL_META_CELL.META_SET.META_SECTION.META_SECT_NAME,
       COUNT(lookup)
FROM ...
WHERE ...
GROUP BY metasect.META_SECT_NAME + " gets from " + lookup.PARENT_META_CELL_META_CELL.META_SET.META_SECTION.META_SECT_NAME

提前感谢您的任何建议:)

4

1 回答 1

0

我用两步法解决了

Dim all = From metasect In DirectCast(Form.ChildDocBox.Tag, META_DOCUMENT).META_SECTIONS
          From metaset In metasect.META_SETS
          From metacell In metaset.META_CELLS
          From lookup In metacell.CHILD_META_CELL_CELLS_LOOKUPS
          Where lookup.PARENT_META_CELL_META_CELL.META_SET.META_SECTION.META_DOCUMENT.META_DOC_ID = docToDelete.META_DOC_ID
          Select lookup


For Each grp As IGrouping(Of String, ICELLS_LOOKUP) In
         all.GroupBy(Function(l) l.CHILD_META_CELL_META_CELL.META_SET.META_SECTION.META_SECT_NAME + " gets from " + l.PARENT_META_CELL_META_CELL.META_SET.META_SECTION.META_SECT_NAME)

    'do some stuff with grp.Key() & grp.Count()'

Next
于 2012-06-22T09:21:05.040 回答