如何在C#中使用Mongo的Aggregate框架在列表字段中累积项目?

问题描述

我有以下实体:

public class MyEntity {
    public string Id { get; set; }
    public string Code { get; set; }
    public decimal Amount { get; set; }
}

public class MyPageItem {
    public string Code { get; set; }
    public decimal Total { get; set; }
    public IList<string> Ids { get; set; } = new List<string>{};
}

以及以下分组:

IMongoCollection<MyEntity> myCollection = MongoClient.GetDatabase("DatabaseName").GetCollection<MyEntity>("MyEntity");
    
myCollection.Aggregate()
                .Sort(new SortDefinitionBuilder<MyEntity>().Ascending("code"))
                .Group(
                        x => x.Code,g => new MyPageItem {
                            Code = g.Select(x => x.Code).Last(),Total = g.Select(x => x.Amount).Sum(),Ids = //how to append Ids in this field?
                        }
                    )
                .ToListAsync();

我想在List<string> Ids中添加所有ID。我该怎么办?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)