RavenDB 使用带分组依据的过滤器

RavenDB using filter with group by

我有一个交易实体。

我可以按 (CustomerCode, CustomerName) 然后 select CustomerCode 和 Total(Amount) 进行分组。

很简单。但是当我想过滤 AtCreated 时。我有一个错误。

未处理的异常。 Raven.Client.Exceptions.InvalidQueryException: Raven.Client.Exceptions.InvalidQueryException: 字段 'AtCreated' 既不是聚合操作也不是 group by key 的一部分 查询:来自 CustomerCode、CustomerName 的交易组,其中 AtCreated >= $p0 select CustomerCode,count() as Total 参数:{"p0":"2019-01-01T00:00:00.0000000"}

    public class Transactions
   {
        public string Id { get; set; }
        public long TransId { get; set; }
        public DateTime AtCreated { get; set; }
        public string CustomerCode { get; set; }
        public string CustomerName { get; set; }
        public string City { get; set; }
        public double Amount { get; set; }
        public string GXF { get; set; }

    }

var transactList = session.Query<Transactions>()
                    .Where(a=>a.AtCreated >= new DateTime(2019,01,01))
                    .GroupBy(a => new {a.CustomerCode, a.CustomerName})
                    .Select(a => new {a.Key.CustomerCode, Total = a.Count()})
                    .ToList();

如何对过滤后的数据进行分组?

谢谢。

创建一个 Map-Reduce 索引,然后对其进行查询。
https://ravendb.net/docs/article-page/4.2/csharp/indexes/map-reduce-indexes

例如,在 this example 中,您可以查询“Category”字段,因为它已被索引(意味着它是 Map-Reduce 索引定义的一部分)

在以下位置查看简短的演示示例: https://demo.ravendb.net/