更新:最后这是一个简单的添加,所以我继续添加它。从 1.0.0.517 开始,下面链接的提案现已在 NuGet 上实施并可用。
您的查询可以是:
var query = client
.Cypher
.Start(
new CypherStartBitWithNodeIndexLookup("left", AUTOINDEX, PrimaryIndexKey, uname),
new CypherStartBitWithNodeIndexLookupWithSingleParameter("right", AUTOINDEX, luceneQuery)
)
.CreateUnique("left-[r:Installed {DeviceId:{DeviceId},OS:{OS}}]->right")
.WithParam("DeviceId", 123)
.WithParam("OS", "Windows 8")
.Return<Software>("right");
你现在不能很好地做到这一点。
是的,Cypher 参数都是安全的,不会被注入。我们以完全不同的结构将它们通过网络传递,使它们与查询文本分开。在 Neo4j 中,它们的存储独立于查询的执行计划。
我在https://bitbucket.org/Readify/neo4jclient/issue/66/support-custom-parameters-in-cypher-fluent打开了一个问题,并提出了语法,以便我们可以实现它。如果您查看提案并在那里合作,我们可以很快得到它。
作为一种解决方法,您可能会这样做:
var query = client
.Cypher
.Start(
new CypherStartBitWithNodeIndexLookup("left", AUTOINDEX, PrimaryIndexKey, uname),
new CypherStartBitWithNodeIndexLookupWithSingleParameter("right", AUTOINDEX, luceneQuery)
)
.CreateUnique("left-[r:Installed {DeviceId:{DeviceId},OS:{OS}}]->right")
.Return<Software>("right")
.Query;
query.QueryParameters.Add("DeviceId", 123);
query.QueryParameters.Add("OS", "Windows 8");
var results = client.ExecuteGetCypherResults<Software>(query);
不过,我在答案框中写了该代码,但尚未对其进行测试,它既可怕又丑陋,我希望您不要使用它。