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

Problem with WHERE in Neo4J, deserialization error

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

我有 3 种类型的节点:Category(重要 属性 name - 字符串),Document(重要 CreatedBy - 代表 User是谁创建的,其他属性在WHERE)之后使用,User(重要Username - 字符串)。文档可以与 CategoryTAG 关系,User 可以与 Category.

INTERESTED_IN 关系

首先我创建了一个查询 return Document 如果它有 TAGCategory 并且如果 UserINTERESTED_IN 这个 Category(注:节点之间我没有多重关系)。还计算了 Category 的连接数,所以如果我有太多 Documents 方法 return 最多只有 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://whosebug.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, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, 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,为什么这个查询不 return 我所期望的?

有了这些东西,检查一下您从客户端生成的什么总是好的。为此,您应该查看 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 属性,但是有在你的 MATCH.

中没有 c