Neo4j 使用Sum()返回计算OrderByDescending
我需要一些帮助将此查询移动到Neo4jClient,请,我正在努力处理总数Neo4j 使用Sum()返回计算OrderByDescending,neo4j,neo4jclient,Neo4j,Neo4jclient,我需要一些帮助将此查询移动到Neo4jClient,请,我正在努力处理总数 MATCH (p:Product)-[viewed:VIEWED]-() return p, count(viewed) as count, sum(viewed.total) as total order by total desc 到目前为止,我已经做到了这一点,但我不能做总数,或OrderByDescending return client.Cypher .Match("(product:
MATCH (p:Product)-[viewed:VIEWED]-()
return p, count(viewed) as count, sum(viewed.total) as total
order by total desc
到目前为止,我已经做到了这一点,但我不能做总数,或OrderByDescending
return client.Cypher
.Match("(product:Product)-[viewed:VIEWED]-()")
.Return((product,viewed) => new ExploreObject
{
Product = product.As<Product>(),
Count = viewed.Count(),
Total = ???
})
.OrderByDescending(???)
.Limit(18)
.Results.ToList();
返回客户端.Cypher
.Match(“(产品:产品)-[查看:查看]-()”)
.Return((产品,已查看)=>新的ExploreObject
{
Product=Product.As(),
Count=已查看。Count(),
总数=???
})
.OrderByDescending(???)
.限额(18)
.Results.ToList();
编辑:将上述代码更改为:
return client.Cypher
.Match("(product:Product)-[viewed:VIEWED]-()")
.Return((product, viewed) => new
{
Product = product.As<Product>(),
Count = viewed.Count(),
Total = Return.As("sum(viewed.total)")
})
.Limit(18)
.Results.ToList();
返回客户端.Cypher
.Match(“(产品:产品)-[查看:查看]-()”)
.返回((产品,查看)=>新建
{
Product=Product.As(),
Count=已查看。Count(),
总计=返回.As(“总和(已查看的.Total)”)
})
.限额(18)
.Results.ToList();
我们仍然会收到错误:“名称“Return”在当前上下文中不存在”
对于total,我尝试了Sum(viewsed.total)和Sum(“viewsed.total”),两者都以错误结尾。使用OrderByDescending,我无法按尚未计算的数字(总数)排序,因此我卡住了,请帮助
不带探索对象的Shaine
return client.Cypher
.Match("(product:Product)-[viewed:VIEWED]-()")
.Return((product,viewed) => new
{
Product = product.As<Product>(),
Count = viewed.Count(),
Total = Return.As("sum(viewed.total)")
})
.OrderByDescending(???)
.Limit(18)
.Results.ToList();
返回客户端.Cypher
.Match(“(产品:产品)-[查看:查看]-()”)
.返回((产品,查看)=>新建
{
Product=Product.As(),
Count=已查看。Count(),
总计=返回.As(“总和(已查看的.Total)”)
})
.OrderByDescending(???)
.限额(18)
.Results.ToList();
下面的代码将返回您的ExploreObject
,其中填充了所需的数据。
Return.As
要求您设置一个类型参数(例如Return.As
),事实上-我很惊讶您居然让它运行了,因为它甚至没有为我编译指定的类型
记住这个案例也很重要。确保所排序的属性与查询/db中的对象具有相同的大小写。例如,您将sum(viewsed.Total)
返回到名为Total
的属性中,因此在本例中,orderby
必须是Total
而不是Total
。不言而喻:
return client.Cypher
.Match("(product:Product)-[viewed:VIEWED]-()")
.Return((product,viewed) => new ExploreObject
{
Product = product.As<Product>(),
Count = viewed.Count(),
Total = Return.As<int>("sum(viewed.Total)") //<-- Need to define type here
})
.OrderByDescending("Total") //<-- Case sensitive
.Limit(18)
.Results.ToList();
遗憾的是,如果没有ExploreObject,“name Return在当前上下文中不存在”,我就无法返回项,因为它需要是强类型列表。有什么想法吗?@ShaineFisher你可以稍后将它们投射到ExploreObject。e、 g..Select(p=>newexploreobject{…})。在可以称之为怪癖的情况下,我仍然从中得到关于Return不存在的错误,这真的很烦人…Return client.Cypher.Match(((product:product)-[viewsed:viewsed]-())。Return((product,viewsed)=>new{Product=Product.As(),Count=viewsed.Count(),Total=Return.As(“sum(viewsed.Total)”)}.Limit(18.Results.ToList();@ShaineFisher您正在使用哪个版本的neo4jclient?这是我糟糕的编程标准(略微继承)这可能导致了混乱,查看。total是图表上的内容,total是w2e作为explore对象的一部分返回的内容,但这是完美的,谢谢。即使在最新版本的代码上,这仍然失败:错误6当前上下文中不存在名称“return”。您是使用
return.as
还是仅T
是int
).NET4.6.00057,根据NuGet,我有1.1.0.9,它引用的dll在bin文件夹中显示为1.1.0.9。您几乎拥有所有内容,Return.As(“sum(viewsed.Total)”)在VS、N4JC dll版本中生成错误
client.Cypher
.Match("(product:Product)-[viewed:VIEWED]-()")
.With("product, viewed, sum(viewed.Total) as summed")
.Return((product, viewed, summed) => new ExploreObject
{
Product = product.As<Product>(),
Count = viewed.Count(),
Total = summed.As<int>()
})
.OrderByDescending("Total")
.Limit(18)
.Results.ToList();