.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; }
}
}
主要
// Create a New Graph Object
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
// Create New Nodes
var lax = client.Create(new Airport() { iata = "lax", name = "Los Angeles International Airport" });
var jfk = client.Create(new Airport() { iata = "jfk", name = "John F. Kennedy International Airport" });
var sfo = client.Create(new Airport() { iata = "sfo", name = "San Francisco International Airport" });
// Create New Relationships
client.CreateRelationship(lax, new flys_toRelationship(jfk) { flightNumber = "1" });
client.CreateRelationship(lax, new flys_toRelationship(sfo) { flightNumber = "2" });
client.CreateRelationship(sfo, new flys_toRelationship(jfk) { flightNumber = "3" });
ただし、問題は、既存のノードに関係を追加する場合です。SNA と EWR の 2 つのノード (空港) だけで構成されるグラフがあり、SNA から EWR への関係 (フライト) を追加したいとします。次のことを試してみましたが、失敗しました。
// Create a New Graph Object
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
Node<Airport> departure = client.QueryIndex<Airport>("node_auto_index", IndexFor.Node, "iata:sna").First();
Node<Airport> arrival = client.QueryIndex<Airport>("node_auto_index", IndexFor.Node, "iata:ewr").First();
//Response.Write(departure.Data.iata); <-- this works fine, btw: it prints "sna"
// Create New Relationships
client.CreateRelationship(departure, new flys_toRelationship(arrival) { flightNumber = "4" });
私が受け取っている2つのエラーは次のとおりです。
1) 引数 1: 「Neo4jClient.Node」から「Neo4jClient.NodeReference」に変換できません
2) メソッド 'Neo4jClient.GraphClient.CreateRelationship(Neo4jClient.NodeReference, TRelationship)' の型引数は、使用法から推測できません。型引数を明示的に指定してみてください。
エラーが参照しているメソッドは、次のクラスにあります。
何か案は?