Neo4jClient Create 包含 JsonIgnore 属性

问题描述 投票:0回答:1

我有一个带有简单属性的 C# 类,我希望在调用 create 时将其保存到节点中。当我使用 Neo4jClient 5.1.3 构建查询时,CREATE 命令中包含一个用 [JsonIgnore] 修饰的复杂类。

这是一个 Person 类:

public class Person {
        public string FirstName { get; set; }
        public string LastName { get; set; }    
        public string Email { get; set; }

        [JsonIgnore]
        public Organization Employer { get; set; }

}

我正在创建它的一个实例:

        var person = new Person
        {
            Email = "[email protected]",
            FirstName = "Job",
            LastName = "Bob",
            Employer = previouslyCreatedEmployer,
        };

...当我运行这个时:

            var query = neo.Client.Cypher
                .Create("(p:Person:Security $object)")
                .WithParams(new Dictionary<string, object> {
                    { "object", person }
                })
                ;

QueryTextForDebug 是这样的:

CREATE (p:Person:Security {
  Email: "[email protected]",
  FirstName: "Job",
  LastName: "Bob",
  Employer: {
    Logo: "",
    IxId: "89becda5-98b4-4623-928f-4c6580cd554f",
    name: "Joe's Bakery"
  },
  IxId: "eb117b37-b062-40e1-b038-1749156ecf7a"
})

由于我在类定义中的 Employer 上有 JsonIgnore 标签,所以我不希望包含它。我缺少什么?谢谢你。

侧面想...也许我不应该在那里有 JsonIgnore 标签,这样我就可以编写更好的查询,对吗?

c# .net neo4j neo4jclient
1个回答
1
投票

Neo4jClient v5.1.3 依赖于 Newtonsoft.Json,请检查

JsonIgnore
来自该库而不是来自
System.Text.Json
。或者指定包含命名空间的完整类型名称:

public class Person 
{
    [Newtonsoft.Json.JsonIgnore]
    public Organization Employer { get; set; }
}
© www.soinside.com 2019 - 2024. All rights reserved.