首页 > 学院 > 开发设计 > 正文

C#同步数据库的数据到Neo4J

2019-11-14 13:58:17
字体:
来源:转载
供稿:网友

数据组件采用https://github.com/Readify/Neo4jClient

在nuget里面有

需要注意的是

 

以下是示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Neo4jClient;
using Neo4jClient.Cypher;

namespace TestNeo4J
{
class PRogram
{
static void Main(string[] args)
{

// Init
var client = new GraphClient(new Uri("http://ip:7474/db/data"));
client.Connect();

var root = client.Get<User>(new NodeReference(0)); //获取根节点,主要是在neoclipse工具里面好浏览,如不考虑浏览,你也可以不加到根节点里面去。

// Create entities
var refA = client.Create(new User() { Name = "User A" });
var refB = client.Create(new User() { Name = "User B" });
var refC = client.Create(new User() { Name = "User C" });

client.CreateRelationship(root.Reference,new ReferralRelationship(refA));
client.CreateRelationship(root.Reference, new ReferralRelationship(refB));
client.CreateRelationship(root.Reference, new ReferralRelationship(refC));


Console.Read();
}

//static void DrawPoints(
}
}

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Neo4jClient;

namespace TestNeo4J
{

public class HatesData
{
public string Reason { get; set; }

public HatesData()
{ }

public HatesData(string reason)
{
this.Reason = reason;
}
}

public class KnowsRelationship : Relationship, IRelationshipAllowingSourceNode<User>,
IRelationshipAllowingTargetNode<User>
{
public static readonly string TypeKey = "KNOWS";

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

public override string RelationshipTypeKey
{
get { return TypeKey; }
}
}

public class ReferralRelationship : Relationship, IRelationshipAllowingSourceNode<User>,
IRelationshipAllowingTargetNode<User>
{
public static readonly string TypeKey = "Referral";

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

public override string RelationshipTypeKey
{
get { return TypeKey; }
}
}

public class User
{
public string Name { get; set; }
}
}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表