Convert Neo4j query in c# using optinal match and merge

半世苍凉 提交于 2020-01-06 07:19:12

问题


Im trying to convert a Neo4j Cypher query that works in Neo4j Desktop but when im trying to use it on c# it doesn't work, can someone help me?

C# query:

        var type = typeof(T).Name;

        var client = Graph.GetClient();

        client.Cypher
            .Match("(location:Location")
            .Where((Location location) => location.GeoNameId == entityGiven.GeoNameId)
            .OptionalMatch("()-[r:HAS]->(location)")
            .Delete("r")
            .With("l")
            .Match("admin:" + type + ")")
            .Where((Admin admin) => admin.GeoNameId == geoNameId)
            .Merge("(admin)-[:HAS]->(location)")
            .ExecuteWithoutResults();

Neo4j Cypher Query:

MATCH (l:Location {GeoNameId: 9410021})
OPTIONAL MATCH ()-[r:HAS]->(l)
DELETE r
WITH l
MATCH (a:Admin2 {GeoNameId:  2367567})
MERGE (a)-[:HAS]->(l);

Already got it just missed a little things that's the solution:

            .Match("(location:Location)")
            .Where((Location location) => location.GeoNameId == entityGiven.GeoNameId)
            .OptionalMatch("()-[r:HAS]->(location)")
            .Delete("r")
            .With("location")
            .Match("(admin:" + type + ")")
            .Where((Admin admin) => admin.GeoNameId == geoNameId)
            .Merge("(admin)-[:HAS]->(location)")
            .ExecuteWithoutResults();

来源:https://stackoverflow.com/questions/57394887/convert-neo4j-query-in-c-sharp-using-optinal-match-and-merge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!