Closed pandabytes closed 1 year ago
The easiest way for you would be to have a LivesInBornInRelationship
that looks like this:
class LivesInBornInRelationship
{
public DateTime? Since { get; set; }
public string HospitalName { get; set; }
}
But that's not sustainable if you increase the numbers of relationship types. At that point you are looking at returning it as a string and parsing it yourself, which is again, not an ideal solution - but to do so, you'd want 3 things, the
public class RelationshipType<TRel>{
public TRel Data {get; set;}
}
<string>
:var results = await _cypherGraphClient.Cypher
.Match($"(p:Person)-[r:LIVES_IN|BORN_IN]->(l:Location)")
.Where((Person p) => p.FirstName == "Jack")
.Return((p, r, l) => new {
Person = p.As<Person>(),
Location = l.As<Location>(),
Relationship = r.As<string>()
})
.ResultsAsync
And then a method to do the conversion:
foreach (var result in results){
switch(result.Type){
case "ACTED_IN":
return JsonConvert.DeserializeObject<RelationshipType<ActedIn>>(result. Data).Data;
case "DIRECTED":
return JsonConvert.DeserializeObject<RelationshipType<Directed>>(result. Data).Data;
default:
throw new ArgumentOutOfRangeException("Type", $"Unknown relationship type {result. Type}");
}
}
Depending on what you're doing with it obviously.
Got it, thank you @cskardon!
In Cypher we can match multiple relationships like this
How can we achieve this using Neo4jClient? This is what I have so far but stuck on retrieving the relationship
Versions: