Neo4j - Neo4jClient - 从 Cypher 结果反序列化

Neo4j - Neo4jClient - Deserialize from Cypher Results

我有一个基本的 Neo4j 数据库,我正在着手将数据从它获取到 .Net Core 下的 C# 中。我在 4.03 DB 上使用螺栓连接。 Windows 10. 我可能还没有掌握图形数据库,但我正在尝试构建一个包含 Positions 的 Person 对象,其中包含 Skill,然后是 Ranks

此代码 returns 6 个 Person 实例(有点担心我有 6 个,但那是个小问题)

var cv = client.Cypher.Match("(person:Person {UserNumber:5})-[:HAS]->(position:Position)<-[:WITHIN]-(skill:Skill)<-[:ON]-(rank:Rank)")
           .Return(person => person.As<Person>());

那个人class

    public class Person
    {
        public Person() {
            RankingProfile = new List<decimal>();
            EmailConfirmed = false;
        }
        …lots of variables (dates, string decimals, boolean)
        public List<decimal> RankingProfile { get; set; }
    }

更改结果格式以尝试构建复合对象,但仅从 Person 开始(已添加 .Results 以获得异常)我得到一个 Type initializer was not callable。异常。

var cv = client.Cypher.Match("(person:Person {UserNumber:5})-[:HAS]->(position:Position)<-[:WITHIN]-(skill:Skill)<-[:ON]-(rank:Rank)")
            .Return(person => new {
                Person = person.As<Person>()
            }).Results;

给我下面的例外。深入研究异常意味着我需要一个我添加的无参数构造函数。现在有点迷路了。

  System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=Exception has been thrown by the target of an invocation.
  Source=Neo4jClient
  StackTrace:
   at Neo4jClient.BoltGraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResults[TResult](CypherQuery query)
   at Neo4jClient.Cypher.CypherFluentQuery`1.get_Results()
   at SonOFMatrix.Controllers.CVController.Get() in C:\Users\Controllers\CVController.cs:line 29
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

  This exception was originally thrown at this call stack:
    [External Code]

    Inner Exception 1:
    MemberAccessException: Type initializer was not callable.
        StackTrace  "   
        at System.Reflection.RuntimeConstructorInfo.ThrowNoInvokeException()
        at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        at System.Reflection.ConstructorInfo.Invoke(Object[] parameters) 
        at Neo4jClient.StatementResultHelper.ConstructNew[T]()  
at Neo4jClient.StatementResultHelper.Parse[T](IRecord record, String identifier, IGraphClient graphClient)" string

因为我使用的日期时间,所以失败了。数据库中的日期时间格式如下(包括时区)“1939-06-23T01:00:00+01:00”。砍掉最后的 +01:00 让它与日期时间为

的 Person 对象一起工作
public DateTime BirthDate { get; set; }

在对象 class 中使用 Neo4j.Driver.V1 允许我指定 ZonedDateTime。它使用包含时区的原始日期格式

public ZonedDateTime BirthDate { get; set; }

非常感谢克里斯,如果没有您的评论,我可能会迷路更长时间。