【发布时间】:2016-02-24 09:38:58
【问题描述】:
一些数据从服务器到达后,我需要对其进行分组。
var result = context.GetData();
Assert.Equal(54, result.Count); // OK
var transactions = result.GroupBy(t => new //BeneficiaryGroup
{
BankAcronym = t.BankAcronym.Substring(4, 4),
DebitDate = t.DebitDate,
Key = t.Key
})
.OrderBy(g => g.Key.BankAcronym)
.ThenBy(g => g.Key.DebitDate)
.ThenBy(g => g.Key.Key)
.ToList();
Assert.Equal( 14, transactions.Count ); // OK
当我按匿名对象分组时,分组已正确完成。
当我按 BeneficiaryGroup 对象分组时,具有完全相同的属性
public class BeneficiaryGroup
{
BankAcronym,
DebitDate,
Key
}
分组未正确完成 - 该组有 54 条记录,与分组前一样。
我想按一个类对数据进行分组,以便将已分组的集合返回给 API 使用者。
任何想法为什么会出现这种奇怪的行为?
【问题讨论】: