RavenDB 使用带有分组依据的过滤器 [英] RavenDB using filter with group by

查看:59
本文介绍了RavenDB 使用带有分组依据的过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个交易实体.

我可以通过 (CustomerCode, CustomerName) 进行分组,然后选择 CustomerCode 和 Total(Amount).

I can make group by by (CustomerCode, CustomerName) then select CustomerCode and Total(Amount).

这很容易.但是当我想过滤 AtCreated 时.我有一个错误.

It is easy. But When I Want to filter AtCreated. I have An Error.

未处理的异常.Raven.Client.Exceptions.InvalidQueryException:Raven.Client.Exceptions.InvalidQueryException:字段AtCreated"既不是聚合操作,也不是按键分组的一部分查询:从交易组按 CustomerCode, CustomerName where AtCreated >= $p0 select CustomerCode, count() as Total参数:{"p0":"2019-01-01T00:00:00.0000000"}

Unhandled exception. Raven.Client.Exceptions.InvalidQueryException: Raven.Client.Exceptions.InvalidQueryException: Field 'AtCreated' isn't neither an aggregation operation nor part of the group by key Query: from Transactions group by CustomerCode, CustomerName where AtCreated >= $p0 select CustomerCode, count() as Total Parameters: {"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();

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

How can I Grouping filtered data?

谢谢.

推荐答案

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

Create a Map-Reduce Index and then query on it.
https://ravendb.net/docs/article-page/4.2/csharp/indexes/map-reduce-indexes

例如在这个例子,你可以查询 'Category' 字段,因为它被索引了(意味着它是 Map-Reduce 索引定义的一部分)

For example, in this example, you can query on 'Category' field because it was indexed (meaning it was part of the Map-Reduce index definition)

请参阅以下简短演示示例:https://demo.ravendb.net/

See short demo examples in: https://demo.ravendb.net/

这篇关于RavenDB 使用带有分组依据的过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆