我有一个初始查询,我想修改它以增加结果的粒度。但是 Visual Studio 告诉我我的查询无效,我不明白为什么。基本上我想根据 2 个属性(列)对我的数据进行分组,并按前 N 个字符对其中一个属性进行分组。
有效的初始查询:
List<PostalCode> codes = (from customer in bd.Customers
group customer by customer.postalcode.Substring(0, postalCodeLength) into postalCodes
select new PostalCode
{
Postal = postalCodes.Key,
Count = postalCodes.Count()
}).ToList();
return codes;
由 ** 标记的查询被 VS2010 标记为错误:
List<PostalCode> codes = (from customer in bd.Customers
group customer by new { **customer.postalcode.Substring(0, postalCodeLength)**, customer.CustomerGroupType}
into postalCodes
select new PostalCode
{
Postal = postalCodes.Key.postalcode,
CustomerGroupType = postalCodes.Key.CustomerGroupType,
Count = postalCodes.Count()
}).ToList();
return codes;