Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 基于组值的查询选择_Vb.net_Entity Framework - Fatal编程技术网

Vb.net 基于组值的查询选择

Vb.net 基于组值的查询选择,vb.net,entity-framework,Vb.net,Entity Framework,我正在使用VB.net,实体框架6和sql server 2008R2,我需要帮助创建查询。 我有一个表:MyTable1,它的结构如下: ID.....group.........vl1 1........1...........7 2........1...........8 3........1...........3 4........2...........2 5........2...........4 我只想选择vl1的组总值超过10的行。 对于上述示例,我们有: Group=1

我正在使用VB.net,实体框架6和sql server 2008R2,我需要帮助创建查询。 我有一个表:MyTable1,它的结构如下:

ID.....group.........vl1
1........1...........7
2........1...........8
3........1...........3
4........2...........2
5........2...........4
我只想选择vl1的组总值超过10的行。 对于上述示例,我们有:

Group=1  Vl1 ( total) = 7+8+3=18
Group=2  Vl1 ( total) = 2+4=6
因此,组1的值大于10,因此应选择组=1的所有行。group2的值为6,因此不应选择group=2的所有行

如何构造这样的查询

谢谢大家!

编辑: 我尝试此查询,但不起作用:

 Dim query as IEnumerable (OF MyTable)
 Query = From t In context.MyTables
         Group By t.group Into Group
         Select Group Where Group.Sum(Function(t2) t2.vl1) > 10

我认为你想要这样的东西,尽管也许有更好的方法来构建它:

Dim query =
    From t In context.MyTables
    Group By t.group Into g = Group
    Where g.Sum(Function(x) x.vl1) > 10
    From t2 In g
    Select t2
g中的From t2 Select t2部分为满足Where子句的每个组执行SelectMany