2017-07-27 37 views
0

我剛開始爲我的neo4j項目使用neo4j客戶端,並且遇到了難以將下面的密碼查詢轉換爲C#的問題。特別是使用分割和toint函數。將包含分割和toint的密碼查詢轉換爲C#

如果你可以幫助我解決這個問題,我現在已經很久沒有試過這個了。我甚至看了其他的網站資源,但從他們身上獲益不多。感謝您的幫助。

MATCH 
    (a:Airport {city:"LAX"})-[:has_flight]->(f:Flight {dep_date:"2017-07-27"})-[:flies_to]->(b:Airport)-[:has_flight]->(f2:Flight)-[:flies_to]->(c:Airport {city:"CLO"}) 
WITH 
    a,b,c,f,f2, 
    split(f.arr_date,"-") as dd, 
    split(f2.dep_date,"-") as dd2 
WHERE 
    toint(dd2[2]) - toint(dd[2])>=0 
    AND toint(dd2[2])- toint(dd[2]) <=1 
RETURN 
    f,f2,a.city,b.city,c.city 
+3

對於我們那些不知道neo4j但知道c#的人,你能用英文寫出算法嗎?這將很容易,幫助將其轉換爲C#的方式.. –

回答

0

你需要打破查詢到它的組成部分,如果你使用的新線,是比較容易:

//MATCH 
match (a:Airport {city:"LAX"})-[:has_flight]->(f:Flight {dep_date:"2017-07-27"})-[:flies_to]->(b:Airport)-[:has_flight]->(f2:Flight)-[:flies_to]->(c:Airport {city:"CLO"}) 

//WITH 
with a,b,c,f,f2,split(f.arr_date,"-") as dd, split(f2.dep_date,"-") as dd2 

//WHERE 
where toint(dd2[2]) - toint(dd[2])>=0 
and toint(dd2[2])- toint(dd[2])<=1 

//RETURN 
return f,f2,a.city,b.city,c.city 

一旦擁有了它非常簡單,轉換爲Neo4jClient,例如:

client.Cypher 
    .Match("(a:Airport {city:"LAX"})-[:has_flight]->(f:Flight {dep_date:"2017-07-27"})-[:flies_to]->(b:Airport)-[:has_flight]->(f2:Flight)-[:flies_to]->(c:Airport {city:"CLO"})") 
    .With("a,b,c,f,f2,split(f.arr_date,"-") as dd, split(f2.dep_date,"-") as dd2") 
    .Where("toint(dd2[2])- toint(dd[2])<=1") 
    .AndWhere("toint(dd2[2])- toint(dd[2])<=1") 
    .Return((f,f2,a.city,b.city,c.city) => new { 
     Flight1 = f.As<Flight>(), 
     Flight2 = f2.Asflight>(), 
     City1 = a.As<Airport>().City, 
     City2 = b.As<Airport>().City, 
     City3 = c.As<Airport>().City 
    }); 

顯然,這種假設你有一個FlightAirport類。