Dex图数据库检索所有节点和边

时间:2014-01-17 00:56:50

标签: c# graph-databases

我知道如何将图形数据库输出到文件(如GraphML文件),但我宁愿遍历节点并将它们作为C#对象,因为我需要在其他地方使用它们。

这样的事情:

var it = graph.GetNodeIterator();
while (it.HasNext()) {
    var node = new MyNodeObject();
    //get attributes or whatever
    nodeList.Add(node);
}
//nodeList now contains all nodes in a List

我找不到方便的方法来执行此操作,而且Dex文档不是很有帮助。很明显,Dex有一些方法可以做到这一点,因为我可以轻松导出到GraphML,但我不想导出到GraphML,然后将GraphML解析为C#对象。

1 个答案:

答案 0 :(得分:0)

我是这样做的,不确定它是否是最佳方式:

//find the type(s) youre looking for based on how you assigned
//them in the first place. you may already know.
var typeIt = graph.FindTypes().Iterator();
while (typeIt.HasNext()) {
   //find your types if you dont know
}

//select the types you want. lets say all of your nodes have one of two types,
//which map to attributes 4 and 3.
var select = graph.Select(4);
//union them
select.Union(graph.Select(3));
//start to iterate
var it = select.Iterator();
while (it.HasNext()) {
    var next = it.Next();
    //map to your own objects using next
}