2014-01-17 49 views
1

我知道如何可以将我的图形数据库输出到文件(如GraphML文件),但我宁愿遍历节点并将它们作为C#对象,因为我需要使用他们在别处。Dex图形数据库检索所有节点和边缘

事情是这样的:

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有这样做的原因,因为我可以轻松导出到GraphML,但我不想导出到GraphML,然后将GraphML解析为C#对象。

回答

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 
}