[英]Group method not recognized in LINQ query
LINQ-newb having trouble using grouping. LINQ-newb无法使用分组。 I'm trying to query an IEnumerable called dosesWithHighestScore.
我正在尝试查询一个名为doseWithWithHighestScore的IEnumerable。
I'm following this example: http://msdn.microsoft.com/en-us/vcsharp/aa336747.aspx#minGrouped 我正在关注以下示例: http : //msdn.microsoft.com/zh-cn/vcsharp/aa336747.aspx#minGrouped
Here's my code: 这是我的代码:
var doseWithLowestVolumeForForm =
from d in dosesWithHighestScore
group d by d.formulation.form into g
select new {
Form = g.Key,
LowDose = g.Group.Min(d => d.doseAdministrableAmount)
};
The use of "Group" is causing this error: 使用“组”会导致此错误:
'System.Linq.IGrouping' does not contain a definition for 'Group' and no extension method 'Group' accepting a first argument of type 'System.Linq.IGrouping' could be found (are you missing a using directive or an assembly reference?) 'System.Linq.IGrouping'不包含'Group'的定义,找不到扩展方法'Group'接受类型为'System.Linq.IGrouping'的第一个参数(是否缺少using指令或程序集引用?)
Here are my usings: 这是我的用法:
using System;
using System.Text;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Collections;
Why am I getting this error? 为什么会出现此错误?
You an get rid of the Group
term in your assignment to LowDose
. 在分配给
LowDose
,您无需使用Group
术语。 In LINQ-to-objects, a group is itself an IEnumerable<>
, so you can apply other LINQ operations to it without any additional qualifiers. 在LINQ-to-objects中,组本身就是
IEnumerable<>
,因此您可以对其应用其他LINQ操作,而无需任何其他限定符。 The Key
property is provided on IGrouping
so that you can access the value by which the group was ... well, grouped. 在
IGrouping
上提供了Key
属性,以便您可以访问对分组进行分组的值。
var doseWithLowestVolumeForForm =
from d in dosesWithHighestScore
group d by d.formulation.form into g
select new {
Form = g.Key,
LowDose = g.Min(d => d.doseAdministrableAmount)
};
The examples on the site that show the use of a Group
property are incorrect. 网站上显示使用
Group
属性的示例不正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.