Question

I have just started learning neo4j with c# client, and I'm having trouble understanding exact usage of list properies.

In the example app Im using (which runs on top of "Cineasts Movies & Actors" dataset) there is a class Actor with following properties:

public class Actor
{
    public String id { get; set; }
    public String name { get; set; }
    public String birthplace { get; set; }
    public String birthday { get; set; }
    public String biography { get; set; }

    public List<Movie> filmography { get; set; }

    public Role playedIn(Movie movie, String role)
    {
        return null;
    }
}

And the class Movie as

public class Movie
{
    public String id { get; set; }
    public String title { get; set; }
    public int year { get; set; }
    public List<Role> cast { get; set; }
}

Now, it fetches an Actor with name==actorName from a database as shown

string actorName = ".*" + actorName + ".*";

Dictionary<string, object> queryDict = new Dictionary<string, object>();
queryDict.Add("actorName", actorName);

var query = new Neo4jClient.Cypher.CypherQuery("start n=node(*) where has(n.__type__) and n.__type__ =~ \".*Person\" and has(n.name) and n.name =~ {actorName} return n",
                                                queryDict, CypherResultMode.Set);

List<Actor> actors = ((IRawGraphClient)client).ExecuteGetCypherResults<Actor>(query).ToList();


foreach (Actor a in actors)
{
    MessageBox.Show(a.name);

}

Now Actor a in a sample above does have its "basic" properties (name, birthday, id,..) but the list filmography is null, I am unable to do the following

foreach (Actor a in actors)
{
    foreach (Movie m in a.filmography)
    {
        MessageBox.Show(m.title);

    }

}

Why to I put this List property in class declaration if it does not fetch this list of related Movie nodes automatically when I fetch Actor, but I must do it from a separate query?

Était-ce utile?

La solution

Neo4jClient is not an ORM, and it doesn't follow relationships for you automatically. It gives you a nice way to execute Cypher queries and deserialize the results into .NET objects.

In Neo4j's model, properties can be a primitive (boolean, byte, short, int, long, float, double, char or string), or an array of one of these primitives. They can't be whole objects.

Now, Neo4jClient doesn't magically implement the graph model for you. You need to work out how to map your model on to the graph.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top