标签: neo4jclient

如何在Neo4j v2中使用Neo4jClient创建节点?

在Neo4j v1.9.x下,我使用了以下类型的代码.

private Category CreateNodeCategory(Category cat)
{
        var node = client.Create(cat,
            new IRelationshipAllowingParticipantNode<Category>[0],
            new[]
            {
                new IndexEntry(NeoConst.IDX_Category)
                {
                    { NeoConst.PRP_Name, cat.Name },
                    { NeoConst.PRP_Guid, cat.Nguid.ToString() }
                }
            });
        cat.Nid = node.Id;
        client.Update<Category>(node, cat);
        return cat;
}
Run Code Online (Sandbox Code Playgroud)

原因是节点ID是自动生成的,我可以稍后使用它来快速查找,在其他查询中启动位等.如下所示:

    private Node<Category> CategoryGet(long nodeId)
    {
        return client.Get<Category>((NodeReference<Category>)nodeId);
    }
Run Code Online (Sandbox Code Playgroud)

这使得以下看起来效果很好.

    public Category CategoryAdd(Category cat)
    {
        cat = CategoryFind(cat);
        if (cat.Nid != 0) { return cat; }
        return CreateNodeCategory(cat);
    }

    public Category CategoryFind(Category cat)
    {
        if (cat.Nid != 0) { return cat; }
        var node …
Run Code Online (Sandbox Code Playgroud)

.net c# neo4j neo4jclient

9
推荐指数
1
解决办法
6057
查看次数

无法加载文件或程序集"Newtonsoft.Json.Net"(HRESULT异常:0x80131040)

当我们通过nuget安装了以前版本的Neo4jClient时,我们看到Newtonsoft.Json版本4.5.0.0作为依赖项安装.我们还使用需要版本6.0.0.0的Newtonsoft.Json的其他软件包,当我们安装它们时,它会覆盖版本4.5.0.0.

当我们启动应用程序时,我们收到此错误:

Unhandled Exception: System.ServiceModel.FaultException`1[System.ServiceModel.Ex
ceptionDetail]: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.
0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.
The located assembly's manifest definition does not match the assembly referenc
e. (Exception from HRESULT: 0x80131040)
Run Code Online (Sandbox Code Playgroud)

我们查看了所有的配置,发现没有引用版本4.5.0.0,但是仔细看了一下Neo4jClient后我们发现了这个.

使用视觉学习工具中的ildasm.exe

这是packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AzureStorageClient" version="0.0.5.1829" targetFramework="net45" />
  <package id="CouchbaseNetClient" version="1.3.4" targetFramework="net45" />
  <package id="Elasticsearch.Net" version="1.0.0-beta1" targetFramework="net45" />
  <package id="Microsoft.Bcl" version="1.1.8" targetFramework="net45" />
  <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.20" targetFramework="net45" />
  <package id="Neo4jClient" version="1.0.0.652" targetFramework="net45" />
  <package …
Run Code Online (Sandbox Code Playgroud)

c# json.net neo4jclient

9
推荐指数
1
解决办法
3万
查看次数

F# - 具有多个返回值的密码查询

鉴于此查询(从这里)

  let pAfollowers =
        client.Cypher
            .Match("n<-[:follows]-e")
            .Where(fun n -> n.Twitter = "tA")
            .Return<Person>("e")
            .Results
            .Select(fun x -> x.Name)
Run Code Online (Sandbox Code Playgroud)

我想调整它并让它返回打包在一起的多个值.不确定类型的外观:

let pAfollowers =
        client.Cypher
            .Match("n<-[r:follows]-e")
            .Where(fun n -> n.Twitter = "tA")
            .Return<???>("n, r, e")
Run Code Online (Sandbox Code Playgroud)

其次,我想知道是否有可能在a之后有一个return语句CreateUnique.我试图调整此查询:

let knows target (details : Knows) source =
        client.Cypher
            .Match("(s:Person)", "(t:Person)")
            .Where(fun s -> s.Twitter = source.Twitter)
            .AndWhere(fun t -> t.Twitter = target.Twitter)
            .CreateUnique("s-[:knows {knowsData}]->t")
            .WithParam("knowsData", details)
            .ExecuteWithoutResults()
Run Code Online (Sandbox Code Playgroud)

让它回归s,t而且details.

f# neo4j neo4jclient

6
推荐指数
1
解决办法
692
查看次数

在Neo4j中将对象存储为属性

我需要在Tile节点中存储一组User对象.每个User对象包含三个原始属性; Id(单个字符串字符串),fName和lName.此对象列表是Tile节点的一个属性,具有多个其他基本属性.整个Tile节点需要序列化为Json,包括嵌套的User对象.

我知道Neo不能将复杂对象存储为属性.我创建了User作为一个单独的节点,id,fName和lName作为属性,我可以通过Cypher返回这些节点.我还可以获取父Tile节点的Json输出结果.(在这种情况下,用户只是一串逗号分隔的alphas).但是如何将用户节点输出嵌套在父节点中呢?

我通过Cypher查询将用户对象与Tile Node中的用户ID字符串相关联,创建了User对象列表(userList).我只需要从两个单独的json输出到一个嵌套输出.

我希望这是足够的细节.我正在使用Neo4j 2.1.6和Neo4jClient.我也在使用.Net 4.0.

neo4j neo4jclient

6
推荐指数
2
解决办法
3621
查看次数

批量插入节点和关系neo4jclient

我在列表中有很多节点和边.目前我正在循环遍历列表并使用非常慢的查询插入每个节点.如何使用neo4jclient执行批量插入?

节点对象:

public class myNode
{
    public int id { get; set; }
    public int floor { get; set; }
    public double x { get; set; }
    public double y { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

插入节点的当前方法:

public static void addNode(GraphClient client, myNode node, string nodeName)
{
    client.Cypher
       .Create("(" + nodeName + ":Node {node})")
       .WithParams(new { node })
       .ExecuteWithoutResults();
}
Run Code Online (Sandbox Code Playgroud)

插入节点列表的当前方法:

List<myNode> nodeList;
foreach(var elem in nodeList)
    addNode(client, elem, "foo");
Run Code Online (Sandbox Code Playgroud)

c# cypher neo4jclient

6
推荐指数
1
解决办法
1079
查看次数

Neo4j over bolt协议具有非常高的延迟

我正在使用Neo4j进行使用官方Neo4j驱动程序for .NET的项目:

https://www.nuget.org/packages/Neo4j.Driver

这个驱动程序适用于bolt协议,我的假设是专用二进制协议比HTTP API更有效.但是从项目开始以来,我注意到Neo4j的延迟相对较高,即使是非常简单的操作也是如此.比如下面的匹配,如果UserID是索引字段,则数据库取30-60ms,否则数据库完全为空:

match(n:User { UserID: 1 }) return n.UserID
Run Code Online (Sandbox Code Playgroud)

在我的本地计算机(接近零网络开销)和我们的生产环境中都会发生此行为.我今天开始调查此问题并发现查询很快返回,但实际流式传输结果需要很长时间.例如,下面的查询需要0.2ms的在本地主机调用返回之前,但然后调用ToArray()result(缓冲的记录,在这种情况下是一个整数字段)增加的时间为60ms.

using (var driver = GraphDatabase.Driver($"bolt://localhost:7687", AuthTokens.Basic("neo4j", "1")))
{    
    using (var session = driver.Session())
    {
        // 0.2ms to return from this call
        var result = session.Run("match(n:User { ID: 1}) return n.ID"); 

        // Uncommenting this makes the whole thing take 60ms
        // result.ToArray(); 
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试了社区赞助的Neo4jClient包,它可以通过HTTP工作:

https://github.com/Readify/Neo4jClient

使用相同的查询,总时间减少到仅0.5ms:

var client = new GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "1");
client.Connect();

client.Cypher.Match("(n:User { …
Run Code Online (Sandbox Code Playgroud)

.net performance latency neo4j neo4jclient

6
推荐指数
1
解决办法
371
查看次数

使用C#中的Neo4jClient在Neo4j中创建节点之间的关系

我正在使用.Net Neo4jClient(http://hg.readify.net/neo4jclient/wiki/Home)与Neo4j合作.在我的代码中,节点是机场,关系是航班.

如果我想同时创建节点和关系,我可以使用以下代码:

public class Airport
{
    public string iata { get; set; }
    public string name { get; set; }
}

public class flys_toRelationship : Relationship, IRelationshipAllowingSourceNode<Airport>, IRelationshipAllowingTargetNode<Airport>
{
    public static readonly string TypeKey = "flys_to";

    // Assign Flight Properties
    public string flightNumber { get; set; }

    public flys_toRelationship(NodeReference targetNode)
        : base(targetNode)
    { }

    public override string RelationshipTypeKey
    {
        get { return TypeKey; }
    }
}
Run Code Online (Sandbox Code Playgroud)

主要

// Create a New Graph Object
var client = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net neo4j neo4jclient

5
推荐指数
1
解决办法
3272
查看次数

将最短路径中的所有节点作为对象列表返回

我有以下Cypher Query,它在Neo4j 2.0.0中运行良好.

MATCH (ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }),
p = shortestPath((ab)-[*..150]-(cd))
RETURN p
Run Code Online (Sandbox Code Playgroud)

Neo4jClient中的以下查询给出错误:功能评估超时.

var pathsQuery =
            client.Cypher
            .Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd))")
            .Return<IEnumerable<PointEntity>>("extract(n in nodes(p) : id(n))");
Run Code Online (Sandbox Code Playgroud)

和之后关于Xclave的另一个类似的工作:

http://geekswithblogs.net/cskardon/archive/2013/07/23/neo4jclient-ndash-getting-path-results.aspx

结果值为:功能评估超时.

var pathsQuery =
            client.Cypher
            .Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd))")
            .Return(p => new PathsResult<PointEntity>
                {
                    Nodes = Return.As<IEnumerable<Node<PointEntity>>>("nodes(p)"),
                }); …
Run Code Online (Sandbox Code Playgroud)

c# shortest-path neo4j graph-databases neo4jclient

5
推荐指数
1
解决办法
1040
查看次数

web api 2中autofac的无参数构造函数错误

嘿伙计我正在使用Autofac作为IOC,这是我的结构:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdTudent.Repo
{
    public interface IRepository
    {
        IAdvertisementRepository Advertisements { get; set; }
        IProfileRepository Profiles { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的存储库类是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdTudent.Repo
{
    public class Repositories : IRepository
    {
        public Repositories(IAdvertisementRepository advertisementRepository,
                            IProfileRepository profileRepository)
        {
            Advertisements = advertisementRepository;
            Profiles = profileRepository;
        }
        public IAdvertisementRepository Advertisements { get; set; }
        public IProfileRepository Profiles { get; set; }
    } …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc dependency-injection autofac neo4jclient asp.net-web-api2

5
推荐指数
1
解决办法
4541
查看次数

Neo4j .NET客户端执行字符串Cypher查询

是否可以使用Neo4j .NET Client或任何其他模块将CYPHER查询作为普通的旧字符串执行?

例如,如果我想在我的图形数据库中添加一些节点并且已经组装了语句,那么有没有办法执行字符串:

CREATE (n:Edit {name:"L-1154LX"});
Run Code Online (Sandbox Code Playgroud)

我正在寻找批处理已经创建的CREATE CYPHER查询列表.

.net c# neo4j cypher neo4jclient

4
推荐指数
1
解决办法
3026
查看次数