我通过传递给类的构造函数来处理cosmos db query的结果:
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 :(得分: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;
}