Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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
C# 从LINQ存储过程中选择不同的计数_C#_Linq_Lambda_Group By_Max - Fatal编程技术网

C# 从LINQ存储过程中选择不同的计数

C# 从LINQ存储过程中选择不同的计数,c#,linq,lambda,group-by,max,C#,Linq,Lambda,Group By,Max,我有一个返回结果集的存储过程,因此: testID(guid)、testName、outcomeID(guid)、outcomeName-字段 testGuid1,testName1,OutcomeGuid1,outcome1 testGuid1、testName1、OutcomeGuid2、outcome2 testGuid1、testName1、OutcomeGuid3、outcome3 testGuid1、testName1、OutcomeGuid4、outcome4 testGuid1,

我有一个返回结果集的存储过程,因此:

testID(guid)、testName、outcomeID(guid)、outcomeName-字段

testGuid1,testName1,OutcomeGuid1,outcome1

testGuid1、testName1、OutcomeGuid2、outcome2

testGuid1、testName1、OutcomeGuid3、outcome3

testGuid1、testName1、OutcomeGuid4、outcome4

testGuid1,testName1,OutcomeGuid5,outcome5

testGuid2,testName2,OutcomeGuid9,outcome9

testGuid2、testName2、OutcomeGuid1、outcome1

testGuid2、testName2、OutcomeGuid3、outcome3

等等。 所以基本上有很多测试,每个测试都有很多结果,一些结果在测试中是常见的

我想做的是在所有测试中获得最大数量的结果,我想用lambda-linq类型的东西来实现这一点。 所以对于上面的结果,我在寻找数字5

如果我这样做:

var Results = dc.getTests(id); 
//need the whole resultsset for binding to something in a mo.
//then would like to do somethign along the lines of:
int count = Results.GroupBy(t=>t.testID).count(*).Max() //or something?
如果我调试,我会得到一个IGrouping Linq,它确实有一个非公共的count属性,但我似乎无法得到它。 无论如何,我希望有更好的方法来获得这个数字。有人能告诉我吗

非常感谢

纳特

然而,请注意,就我个人而言,我正在寻找一种在数据库中实现这一点的方法,而不是通过网络获取所有数据来获取单个数字。一个好的选择是将代码推送到UDF中,并更改SP,因此只需
SELECT*FROM dbo.YourUdf(args)
——原因是UDF是可组合的,因此您可以将UDF映射到数据上下文中,并具有:

var max = db.MyUdf(args).GroupBy(t=>t.testID).Max(grp => grp.Count());

(即相同的代码),它将在服务器上执行工作,只需通过网络返回一个号码。

嗨,马克,谢谢。实际上,我并不是为了得到那个数字而使用那个查询,数据被绑定到东西上,我只是想我可以从结果集中算出那个数字,而不是运行一个新的查询来得到那个数字。@nat-sure;在这种情况下是有道理的。
var max = db.MyUdf(args).GroupBy(t=>t.testID).Max(grp => grp.Count());