2017-08-30 115 views
0

我與宇宙數據庫查詢的結果正與graphson結果工作:通過傳遞到一類的構造函數在宇宙DB

public Session GetASession() 
{ 
    IDocumentQuery<dynamic> query = database.Client.CreateGremlinQuery<dynamic>(database.Graph, $"g.V()"); 
    var session = new Data(query.ExecuteNextAsync().Result.FirstOrDefault()); 
    return session; 
} 

哪個Session類實現的喜歡以下內容:

public Class Session 
{ 
    dynamic graphson; 
    public Session(dynamic graphson) 
    { 
     this.graphson = graphson; 
    } 
    public string Id 
    { 
     get 
     { 
      return (string)graphson.id; 
     } 
     set 
     { 
      graphson.id = value; 
     } 
    } 
} 

問題是當調用GetASession函數時,儘管查詢從db獲得了一些會話,但Id在返回的會話中不可用並且以這種方式得到錯誤。因此,問題在哪裏?

回答

0

由於我發現從查詢返回的對象是弱引用對象,所以如果我們不將它分配給一個變量,它將被丟棄。因此,解決方案是:

public Session GetASession() 
{ 
    IDocumentQuery<dynamic> query = database.Client.CreateGremlinQuery<dynamic>(database.Graph, $"g.V()"); 
    var result = query.ExecuteNextAsync().Result.FirstOrDefault(); 
    var session = new Data(result); // this solves the problem 
    return session; 
}