我有一些数据存储为neo4j节点。此节点具有一些未由关联的C#类描述的属性,因此在neo4jclient查询返回时不会自动映射回该类。
举个例子,这个C#类:
public class Node {
public string name;
public int number;
public CustomClass data;
}
存储在neo4j中,然后使用以下neo4jclient流畅代码检索:
var query = client.Cypher
.Match("(n:Node)")
.Return(n => n.As<Node>())
.Results;
将使用名称和编号填充Node对象,但保留对CustomClass对象的空引用。
为了解决这个问题,我将CustomClass序列化为JSON字符串,并将其作为字符串属性存储在neo4j中。为了反序列化这个JSON类,我需要从存储在neo4j中的Node中检索JSON字符串属性。
neo4jclient文档建议如下:
.Return(() => new {
JSONString = Return.As<string>("matchedNode.JSONProperties")
})
但是这是无效的代码。在该上下文中不存在 Return
之后的JSONString =
。
请参阅答案。
如何从数据库中获取JSONPropeties字符串?
答案 0 :(得分:0)
给定的代码完全按预期工作,您只需要包含正确的neo4jclient引用。在这种情况下,它是
CHANGE_TOTAL = (float(input('type in the change total ')))
def main():
value_1 = (float(input('type in the first value ')))
value_2 = (float(input('type in the second value ')))
value_3 = (float(input('type the third value ')))
values_average(value_1,value_2,value_3)
def values_average(a,b,c):
total = (a+b+c)
if total > CHANGE_TOTAL:
print ('there\'s not change availibility at the moment plase wait')
main()
else:
print ('your change is being process plase wait a moment')
change_due(total)
def change_due(items_cost):
input ('"press enter"')
money_received = (float(input('type in the amount of money received ')))
change = (money_received - items_cost)
print ('your change is', change)
change_total_aft_trans(change)
def change_total_aft_trans(a):
change_left = (CHANGE_TOTAL - a)
print ('the change left is', change_left)
main()
,using Neo4jClient.Cypher;
不再是未定义的。如果您需要访问所有匹配的元素,这也是Return
类的位置。
答案 1 :(得分:0)
除了添加
之外,还有你的答案 using Neo4jClient.Cypher
您也可以选择仅返回Node
属性,如下所示:
var query = client.Cypher
.Match("(n:Node)")
.Return(n => n.As<Node>().name) //<-- returning just the property
.Results;