C# Neo4jClient创建和更新关系
我有一个Neo4j图形数据库,可以通过访问。(它是Neo4j REST api的.NET客户端) 有一个新的开始 我所做的 与数据库的连接正常C# Neo4jClient创建和更新关系,c#,.net,relationship,neo4j,neo4jclient,C#,.net,Relationship,Neo4j,Neo4jclient,我有一个Neo4j图形数据库,可以通过访问。(它是Neo4j REST api的.NET客户端) 有一个新的开始 我所做的 与数据库的连接正常 Client = new GraphClient(new Uri("http://localhost:7474/db/data")); Client.Connect(); 这样我可以插入节点 Client.Create(new myNodeClass { name = "Nobody" }); 。。。并查询它们 Node<myNodeClass
Client = new GraphClient(new Uri("http://localhost:7474/db/data"));
Client.Connect();
这样我可以插入节点
Client.Create(new myNodeClass { name = "Nobody" });
。。。并查询它们
Node<myNodeClass> Node = Client.Get<WordNode>(138);
return Node.Data.name;
你能给我一个添加和更新(数字)关系的例子吗?你可以看看测试,或者联系Neo4j邮件列表的作者groups.google.com/group/Neo4j?在测试用例中可以找到很多。。。例如:
我也被卡住了,然后我意识到我需要在CreateRelationship方法中指定源节点引用参数的类型参数 在本例中,我创建了关系。我还没有更新关系 披露(它作为运行VisualStudio2012的控制台应用程序在我的机器上运行,YMMV)
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Net.Http;
使用Neo4jClient;
名称空间Neo4jClientExample
{
类MyConsoleProgram
{
专用GraphClient客户端{get;set;}
静态void Main(字符串[]参数)
{
试一试{
GraphClient=新GraphClient(新Uri(“http://localhost:7474/db/data"));
client.Connect();
Us Us=新的Us{Name=“我们就是我们”};
NodeReference usRef=client.Create(美国);
WriteLine(“us node.id:{0}”,usRef.id);
var queryUs=client.Cypher.Start(“n”,“node”(+usRef.Id+))。返回(“n”);
WriteLine(“Us节点名称:{0}\n”,queryUs.Results.AsEnumerable().First().Data);
AllYourBase AllYourBase=newallyourbase{Name=“我们都是你的基地”};
noderereference allYourBaseRef=client.Create(allYourBase);
WriteLine(“AllYourBase node.id:{0}”,allYourBaseRef.id);
var queryAllYourBase=client.Cypher.Start(“n”,“node”(+allYourBaseRef.Id+))。Return(“n”);
WriteLine(“AllYourBase节点名称:{0}\n”,queryAllyUrbase.Results.AsEnumerable().First().Data);
RelationshipReference areBelongToRef=client.CreateRelationship(allYourBaseRef,new AreBelongTo(usRef));
var query=client.Cypher.Start(“allyourbase”、“node”(+allYourBaseRef.Id+))).Match(“allyourbase-[:ARE\u-atto]->us”).Return(“allyourbase”);
query.ExecuteWithoutResults();
WriteLine(“查询属于我们的所有基的结果:{0}”,query.Results.AsEnumerable().First().Data.Name);
}
捕获(例外情况除外)
{
Console.WriteLine(“{0}”,例如Message);
WriteLine(“{0}”,例如InnerException);
}
Console.ReadKey();
}
}
美国公众阶级
{
公共字符串名称{get;set;}
公共服务
{
}
}
公共类AllYourBase
{
公共字符串名称{get;set;}
public AllYourBase()
{
}
}
公共类属于:关系、IRelationshipAllowingSourceNode、,
IRelationshipAllowingTargetNode
{
公共AreBelongTo(节点引用目标节点)
:base(targetNode)
{}
public const string TypeKey=“您是否属于”;
公共重写字符串RelationshipTypeKey
{
获取{return TypeKey;}
}
}
Great find!它提供了简单调用的良好概述。
Client.CreateRelationship(Neo4jClient.NodeReference<TSourceNode>, TRelationship);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Neo4jClient;
namespace Neo4jClientExample
{
class MyConsoleProgram
{
private GraphClient Client {get;set; }
static void Main(string[] args)
{
try{
GraphClient client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
Us us = new Us { Name = "We are Us" };
NodeReference<Us> usRef = client.Create(us);
Console.WriteLine("us node.id: {0}", usRef.Id);
var queryUs = client.Cypher.Start("n", "node(" + usRef.Id + ")").Return<Node<Us>>("n");
Console.WriteLine("Us node name: {0}\n", queryUs.Results.AsEnumerable<Node<Us>>().First().Data);
AllYourBase allYourBase = new AllYourBase { Name = "We are all your base" };
NodeReference<AllYourBase> allYourBaseRef = client.Create(allYourBase);
Console.WriteLine("AllYourBase node.id: {0}",allYourBaseRef.Id);
var queryAllYourBase = client.Cypher.Start("n", "node(" + allYourBaseRef.Id + ")").Return<Node<AllYourBase>>("n");
Console.WriteLine("AllYourBase node name: {0}\n", queryAllYourBase.Results.AsEnumerable<Node<AllYourBase>>().First().Data);
RelationshipReference areBelongToRef = client.CreateRelationship(allYourBaseRef, new AreBelongTo(usRef));
var query = client.Cypher.Start("allyourbase", "node(" + allYourBaseRef.Id + ")").Match("allyourbase-[:ARE_BELONG_TO]->us").Return<Node<AllYourBase>>("allyourbase");
query.ExecuteWithoutResults();
Console.WriteLine("Result of querying for all your base that belongs to us: {0}", query.Results.AsEnumerable<Node<AllYourBase>>().First().Data.Name);
}
catch(Exception ex)
{
Console.WriteLine("{0}", ex.Message);
Console.WriteLine("{0}", ex.InnerException);
}
Console.ReadKey();
}
}
public class Us
{
public string Name {get; set;}
public Us()
{
}
}
public class AllYourBase
{
public string Name { get; set; }
public AllYourBase()
{
}
}
public class AreBelongTo : Relationship, IRelationshipAllowingSourceNode<AllYourBase>,
IRelationshipAllowingTargetNode<Us>
{
public AreBelongTo(NodeReference targetNode)
: base(targetNode)
{}
public const string TypeKey = "ARE_BELONG_TO";
public override string RelationshipTypeKey
{
get { return TypeKey; }
}
}