Neo4J 中的 WHERE 问题,反序列化错误

问题描述

我在 .NET Core Web 应用程序中使用 Neo4JClient(我在 VisualStudio 2019 版模板中创建了它),并且我的代码按我的示例预期工作。

我有 3 种类型的节点:Category(important property name - string),Document(important CreatedBy - 代表创建者的名字 User它,在 WHERE),User(important Username - string) 之后使用其他属性。文档可以与 TAG 具有 Category 关系,而 User 可以与 INTERESTED_IN 具有 Category 关系。

首先我创建了一个查询来返回 Document 如果它有 TAGCategory 并且如果 UserINTERESTED_IN 这个 Category(注意:我在节点之间没有多重关系)。与 Category 的连接数也被计算在内,所以如果我有太多的 Documents 方法,大多数连接只返回 10 个。

    public async Task<IActionResult> GetNewsFeed(string username)
{
    string match = $"(a:User{{Username: '{username}'}})-[:INTERESTED_IN]->(res:Category)<-[:TAG]-(b:Document)";
    string where = $"NOT(b.isArchived AND c.isArchived AND b.CreatedBy =~ '{username}')";
    string with = "b.name AS name,b.CreatedBy AS creator,b.Pictures AS pictures,b.Paragraphs AS paragraphs,COUNT(res) AS interest1";
    
    var result = _context.Cypher.Match(match)
                             //.Where(where)
                               .With(with)
                               .Return((name,creator,pictures,paragraphs,interest1)=> new SimpleNewsFeedDTO { 
                                                                                                        Name = name.As<string>(),Creator = creator.As<string>(),Pictures = pictures.As<string[]>(),Paragraphs = paragraphs.As<string[]>(),Interest = interest1.As<int>() })  
                               .OrderBy("interest1 DESC")
                               .Limit(10)
                               .ResultsAsync);
    return new JsonResult(await result);
}

当我提供正确的用户名时,我可以按正确的顺序查看结果,但我也想过滤该用户创建的文档(我想排除用户创建的文档),但是当我取消注释 Where 并发送请求时,我得到以下错误

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.ArgumentException: Neo4j returned a valid response,however Neo4jClient was unable to deserialize into the object structure you supplied.

First,try and review the exception below to work out what broke.

If it's not obvIoUs,you can ask for help at http://stackoverflow.com/questions/tagged/neo4jclient

Include the full text of this exception,including this message,the stack trace,and all of the inner exception details.

Include the full type deFinition of ExtraBlog.DTOs.SimpleNewsFeedDTO.

Include this raw JSON,with any sensitive values replaced with non-sensitive equivalents:

 (Parameter 'content')
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'input')
   at System.Text.RegularExpressions.Regex.Replace(String input,String replacement)
   at Neo4jClient.Serialization.CommonDeserializerMethods.ReplaceAllDateInstancesWithNeoDates(String content)
   at Neo4jClient.Serialization.CypherjsonDeserializer`1.Deserialize(String content,Boolean isHttp)
   --- End of inner exception stack trace ---
   at Neo4jClient.Serialization.CypherjsonDeserializer`1.Deserialize(String content,Boolean isHttp)
   at Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResultsAsync[TResult](CypherQuery query)
   at ExtraBlog.Controllers.UserController.GetNewsFeed(String username) in E:\GithubRepo\NapredneBaze\Neo4JProject\extra-blog\ExtraBlog\Controllers\UsersController.cs:line 39
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper,ObjectMethodExecutor executor,Object controller,Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker,ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterasync>g__Awaited|10_0(ControllerActionInvoker invoker,Task lastTask,State next,Scope scope,Object state,Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next,Scope& scope,Object& state,Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterasync>g__Awaited|13_0(ControllerActionInvoker invoker,Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker,Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next,Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker,Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker,Task task,Idisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint,Task requestTask,ILogger logger)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

此外,当我在 Neo4J 浏览器中运行类似的程序时,无论是否使用 WHERE,都会得到相同的结果:

MATCH (a:User{Username: 'NN'})-[:INTERESTED_IN]->(res:Category)<-[t:TAG]-(b:Document)
WHERE (NOT(b.isArchived AND res.isArchived AND b.CreatedBy =~ 'NN'))
WITH b,COUNT(res) AS interest1
RETURN b.name,interest1
ORDER BY interest1 DESC
LIMIT 10

所以我的问题是:为什么我不能在 Visual Studio 中运行我的方法,为什么这个查询没有返回我期望的结果?

解决方法

有了这些东西,检查什么从客户端生成总是好的。为此,您应该查看 query.DebugQueryText 属性。如果这样做,您将看到生成的查询如下所示:

MATCH (a:User{Username: 'NN'})-[:INTERESTED_IN]->(res:Category)<-[:TAG]-(b:Document)
WHERE NOT(b.isArchived AND c.isArchived AND b.CreatedBy =~ 'NN')
WITH b.name AS name,b.CreatedBy AS creator,b.Pictures AS pictures,b.Paragraphs AS paragraphs,COUNT(res) AS interest1
RETURN name AS Name,creator AS Creator,pictures AS Pictures,paragraphs AS Paragraphs,interest1 AS Interest
ORDER BY interest1 DESC
LIMIT 10

如果您尝试在浏览器中执行它 - 它不会起作用,这是因为您使用别名 c 来访问 isArchived 属性,但没有 c在您的MATCH中。