我是Neo4j / Neo4jClient的新手,如果不存在则尝试创建一个节点。我在使用下面提到的查询时遇到异常。请帮助我!
这是创建节点时捕获的Exception-
Neo4jClient.NeoException: CypherTypeException: Property values can only be of primitive types or arrays thereof
如果不存在,这是为创建节点而编写的代码。 Neo4jClient查询
graphClient.Cypher
.Merge("(u:User{ name: '" + user.Contact.Mobile.Number + "' }) ON CREATE SET u = {user}")
.WithParam("user", user)
.Return<Node<User>>("u")
.Results
.Single();
这是我的User实体-
public partial class User
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("firstName")]
public string FirstName { get; set; }
[JsonProperty("middleName", NullValueHandling = NullValueHandling.Ignore)]
public string MiddleName { get; set; }
[JsonProperty("lastName", NullValueHandling = NullValueHandling.Ignore)]
public string LastName { get; set; }
[JsonProperty("contact")]
public Contact Contact { get; set; }
[JsonProperty("age")]
public long Age { get; set; }
[JsonProperty("gender")]
public string Gender { get; set; }
[JsonProperty("joiningDate")]
public DateTime JoiningDate { get; set; }
[JsonProperty("modifiedDate")]
public DateTime ModifiedDate { get; set; }
[JsonProperty("hobbies", NullValueHandling = NullValueHandling.Ignore)]
public List<string> Hobbies { get; set; }
[JsonProperty("profilePictures", NullValueHandling = NullValueHandling.Ignore)]
public List<ProfilePicture> ProfilePictures { get; set; }
[JsonProperty("languages", NullValueHandling = NullValueHandling.Ignore)]
public List<string> Languages { get; set; }
}
public partial class Contact
{
[JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)]
public string Email { get; set; }
[JsonProperty("alternateEmail", NullValueHandling = NullValueHandling.Ignore)]
public string AlternateEmail { get; set; }
[JsonProperty("mobile")]
public Mobile Mobile { get; set; }
[JsonProperty("alternateMobile", NullValueHandling = NullValueHandling.Ignore)]
public Mobile AlternateMobile { get; set; }
}
public partial class Mobile
{
[JsonProperty("contryCode")]
public string ContryCode { get; set; }
[JsonProperty("number")]
public long Number { get; set; }
}
public partial class ProfilePicture
{
[JsonProperty("url")]
public string URL { get; set; }
[JsonProperty("sortOrder")]
public long SortOrder { get; set; }
}
[您有很多非本原语,例如Contact
,ProfilePicture
-您有几个选项,第一个是将它们提取为单独的节点,在这种情况下,您将[JsonIgnore]
在它们上方,以确保默认情况下未对它们进行序列化。
OR
您自定义编写一个序列化程序-将使用属性并将其作为Json对象放入(通常)。这个问题Storing a Dictionary in a Node给出了一个例子。
在两个选项中,如果要查询其中的值,则第一个是最佳选项。例如,您要通过EmailAddress进行查询,并且该查询位于Contact
类中。
[还有第三个选项-只是两者的组合。提取您要查询的内容,序列化其余内容。