你的位置:首页 > ASP.net教程

[ASP.net教程]C#同步数据库的数据到Neo4J


数据组件采用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; }
}
}