2014-01-17 86 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 
}