neo4j使用列表属性 [英] neo4j use of list properties

查看:791
本文介绍了neo4j使用列表属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用c#客户端学习neo4j,但在理解列表属性的确切用法时遇到了麻烦.

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

在我使用的示例应用程序(在电影和演员"数据集的顶部运行)中,有一个具有以下属性的Actor类:

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;
    }
}

电影类为

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

现在,它如图所示从数据库中获取一个name == actorName的Actor

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);

}

上面示例中的Actor a确实具有其基本"属性(名称,生日,id等),但是列表filmography为空,我无法执行以下操作

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);

    }

}

如果我在获取Actor时没有自动获取相关的Movie节点列表,但为什么我必须将此List属性放入类声明中,但是我必须通过单独的查询来执行此操作?

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?

推荐答案

Neo4jClient不是ORM,它不会自动为您跟踪关系.它为您提供了一种执行Cypher查询并将结果反序列化为.NET对象的好方法.

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.

在Neo4j的模型中,属性可以是原始的(booleanbyteshortintlongfloatdoublecharstring),或这些原语之一的数组.它们不能是完整的对象.

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.

现在,Neo4jClient不会为您神奇地实现图形模型.您需要弄清楚如何将模型映射到图形上.

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.

这篇关于neo4j使用列表属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆