After some struggle to get it right I manage to save relationships with properties to a Neo4j db with Neo4jClient. The problem arrises when I want to read those relationships back. Suddenly the query which worked like a charm before does not return my users anymore? No exceptions are thrown, the call just silently returns empty :( I read about possible deserializing problems and added the parameterless constructor to the relationship class but no luck.
public class UserHasHomeCity : Relationship<HasHomeCity>, IRelationshipAllowingSourceNode<UserEntity>, IRelationshipAllowingTargetNode<CityEntity>
{
public UserHasHomeCity()
: base(-1, null)
{
}
public UserHasHomeCity(NodeReference targetNode, HasHomeCity data)
: base(targetNode, data)
{
}
public const string TypeKey = "USER_HAS_HOME_CITY";
public override string RelationshipTypeKey
{
get { return TypeKey; }
}
}
public class HasHomeCity
{
public string Date { get; set; }
public HasHomeCity()
{ }
public HasHomeCity(string date)
{
this.Date = date;
}
}
And here is my query:
var graphResults = graphClient.Cypher
.Match("(user:User)-[:USER_IS_IN_ROLE]-(role:Role)",
"(user:User)-[:USER_HAS_HOME_CITY]-(homeCity:City)-[:CITY_IS_IN_COUNTRY]-(homeCountry:Country)",
"(user:User)-[:USER_HAS_LIVING_CITY]-(livingCity:City)-[:CITY_IS_IN_COUNTRY]-(livingCountry:Country)")
.Where((UserEntity user) => user.Id == id)
.Return((user, role, homeCity, livingCity, homeCountry, livingCountry) => new
{
User = user.As<UserEntity>(),
Roles = role.CollectAs<RoleEntity>(),
HomeCity = homeCity.As<CityEntity>(),
LivingCity = livingCity.As<CityEntity>(),
HomeCountry = homeCountry.As<CountryEntity>(),
LivingCountry = livingCountry.As<CountryEntity>()
}).Results;
(user:User)-[r:USER_IS_IN_ROLE]->(role:Role)
returningr
- Charlotte Skardon