Question

I am building a social graph application using Neo4jClient to store data and I am trying to come up with the best strategy to model where a user has worked and currently works. So my User is connected with the relationship "USER_WORK" to several Work nodes which has StartDate/EndDate properties. If EndDate is not set I want to add another relationship "CURRENT" between the user/work node to be able to fetch only current work places in an efficient way.

For some reason Neo4jClient does not let me do this? Below query executes without exceptions and the work node and all relationships except "CURRENT" is added (and yes I have checked that there is no problem with the EndDate logic:) I have also tried using Create instead of CreateUnique but that doesn't solve the problem :(

var query = graphClient.Cypher
            .Match("(city:City)", "(profession:Profession)", "(company:Company)", "(user:User)")
            .Where((CityEntity city) => city.Id == model.CityId)
            .AndWhere((ProfessionEntity profession) => profession.Id == model.ProfessionId)
            .AndWhere((CompanyEntity company) => company.Id == model.CompanyId)
            .AndWhere((UserEntity user) => user.Id == model.UserId)
            .Merge("(work:Work { Id: {Id} })")
            .OnCreate()
            .Set("work = {entity}")
            .WithParams(new
            {
                Id = entity.Id,
                entity
            })
            .CreateUnique("work-[:WORK_AS_PROFESSION]->profession")
            .CreateUnique("work-[:WORK_AT_COMPANY]->company")
            .CreateUnique("work-[:WORK_IN_CITY]->city")
            .CreateUnique("user-[:USER_WORK]->work");

        if (model.EndDate == DateTime.MinValue)
        { 
            query.CreateUnique("user-[:CURRENT]->work");
        }

query.ExecuteWithoutResults();
Was it helpful?

Solution

When you call CreateUnique to create the user-[:CURRENT]->work relationship, it's not actually being appended to the query. What you need to change that line to is:

query = query.CreateUnique("user-[:CURRENT]->work");

Which is what is happening for all the fluent methods chained in the first query you write out. The easiest way to spot these things is stick a breakpoint on the query.ExecuteWithoutResults(); method and when VS breaks there, hover over query and see if the text matches what you think it should.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top