Neo4j 第一次查询 returns 多条记录

Neo4j Query returns multiple records after first time

我将 Neo4j 客户端与 ASP.NET MVC 一起使用,我有这个查询显示 运行ge 日期内的用户事件,当我 运行 这个查询第一次它 returns 事件正确但是当我调用我的 ajax 到 运行 事件再次查询给我的记录是第一次的两倍。我已经逐行跟踪查询,但一切似乎都运行良好,我不得不说我是第一次使用 Union 可以查看我的查询并告诉我是否有问题吗?

var q = new CypherFluentQuery(client) as ICypherFluentQuery;
q = q.Match("(y:Year)--(m:Month)--(d:Day)--(h:Hour)--(sr:ServiceRequest)-[" + Relations.EXPERT_ASSIGN_TO_SQ.ToString() + "]-(u:User)")
     .Where("y.value >= {param}").WithParam("param", dt1.Year)
     .AndWhere("m.value >= {param2}").WithParam("param2", dt1.Month)
     .AndWhere("d.value >= {param4}").WithParam("param4", dt1.Day)
     .AndWhere("u.Id = {param10}").WithParam("param10", Id)
     .With("y,m,d,h,sr,u")
     .Match("(sr)-[:" + Relations.SC_HAS_SQ.ToString() + "]-(c2:ServiceCategory)-[:" + Relations.SC_IS_SC_CHILD.ToString() + "*]-(c3:ServiceCategory)")
     .ReturnDistinct((y, m, d, h, sr, c2, c3) => new
     {
         Year = y.As<RootTree>().value,
         Month = m.As<RootTree>().value,
         Day = d.As<RootTree>().value,
         Hour = h.As<RootTree>().value,
         serviceRequest = sr.As<ServiceRequest>(),
         ServiceCategory = c2.As<OnDemandService>(),
         ServiceParent = c3.As<OnDemandService>()

     })
     .UnionAll()
     .Match("(yy:Year)--(mm:Month)--(dd:Day)--(hh:Hour)--(sr2:ServiceRequest)-[" + Relations.EXPERT_ASSIGN_TO_SQ.ToString() + "]-(u)")
     .Where("yy.value <= {param7}").WithParam("param7", dt2.Year)
     .AndWhere("mm.value >= {param8}").WithParam("param8", dt2.Month)
     .AndWhere("dd.value >= {param9}").WithParam("param9", dt2.Day)
     .With("yy,mm,dd,hh,sr2,u")
     .Match("(sr2)-[:" + Relations.SC_HAS_SQ.ToString() + "]-(c2:ServiceCategory)-[:" + Relations.SC_IS_SC_CHILD.ToString() + "*]-(c3:ServiceCategory)");

var query = q.ReturnDistinct((yy, mm, dd, hh, sr2, c2, c3) => new
{
    Year = yy.As<RootTree>().value,
    Month = mm.As<RootTree>().value,
    Day = dd.As<RootTree>().value,
    Hour = hh.As<RootTree>().value,
    serviceRequest = sr2.As<ServiceRequest>(),
    ServiceCategory = c2.As<OnDemandService>(),
    ServiceParent = c3.As<OnDemandService>()
}).Results.ToList();

跟踪查询:

MATCH (y:Year)--(m:Month)--(d:Day)--(h:Hour)--(sr:ServiceRequest)-[EXPERT_ASSIGN_TO_SQ]-(u:User)
WHERE y.value >= 2017
AND m.value >= 5
AND d.value >= 16
AND u.Id = "c0dc7cbe-5626-4012-a5ea-72c1cfce2461"
WITH y,m,d,h,sr,u
MATCH (sr)-[:SC_HAS_SQ]-(c2:ServiceCategory)-[:SC_IS_SC_CHILD*]-(c3:ServiceCategory)
RETURN distinct y.value AS Year, m.value AS Month, d.value AS Day, h.value AS Hour, sr AS serviceRequest, c2 AS ServiceCategory, c3 AS ServiceParent
UNION ALL
MATCH (yy:Year)--(mm:Month)--(dd:Day)--(hh:Hour)--(sr2:ServiceRequest)-[EXPERT_ASSIGN_TO_SQ]-(u)
WHERE yy.value <= 2017
AND mm.value >= 5
AND dd.value >= 9
WITH yy,mm,dd,hh,sr2,u
MATCH (sr2)-[:SC_HAS_SQ]-(c2:ServiceCategory)-[:SC_IS_SC_CHILD*]-(c3:ServiceCategory)
RETURN distinct yy.value AS Year, mm.value AS Month, dd.value AS Day, hh.value AS Hour, sr2 AS serviceRequest, c2 AS ServiceCategory, c3 AS ServiceParent

更新

我已经 运行 对 neo4j 本身的查询多次 returns 正确,只有在我的应用程序中使用 neo4jClient

查询 运行s 时才会发生这种情况

实际上很简单,因为我使用了 union all 我将其更改为 union 并且它起作用了。