ra0o0f / arangoclient.net

ArangoDB .NET Client with LINQ support
Apache License 2.0
99 stars 37 forks source link

Get Results Of Query as JSON/String #113

Open Rleahy opened 5 years ago

Rleahy commented 5 years ago

Hi i'm trying to get the results of a query as follows

        string Query = "FOR doc IN @type RETURN {Prob: doc.belief.Probability, From: doc._from, To:doc._to, Key:doc._key}";

        List<QueryParameter> perams = new List<QueryParameter>();
        QueryParameter qp = new QueryParameter();
        qp.Name = "type";
        qp.Value = ActualEdge.ToString();
        perams.Add( qp );

        ICursor<string> Obj = GraphDB.DB.CreateStatement<string>(Query,perams);

Because i do no know the type at compile time i can't return the results using generics. How would i get the result of this query as a raw string or dynamic object?

When i attempt to cast to string or dynamic i get errors as soon as i start trying to pull the results i get ArangoDB.Client.ArangoServerException 'AQL: collection or array expected as operand to FOR loop; you specified type 'string' with content '"Binds"' (while optimizing ast). ErrorNumber: 1563 HttpStatusCode: 400'

ra0o0f commented 5 years ago

@Rleahy you can either use json.net JObject or dynamic

JObject version

var result = GraphDB.DB.CreateStatement<JObject>(Query,perams).ToList();
foreach (var r in result)
{
    double Prob = r.Value<double>("Prob");
}

dynamic version

var result = GraphDB.DB.CreateStatement<dynamic>(Query,perams).ToList();
foreach (var r in result)
{
    double Prob = r.Prob;
}
Rleahy commented 5 years ago

Thanks for the fast reply much appreciated its working now :)

On Mon, Nov 5, 2018 at 1:23 PM raoof hojat notifications@github.com wrote:

@Rleahy https://github.com/Rleahy you can either use json.net JObject or dynamic

JObject version

var result = GraphDB.DB.CreateStatement(Query,perams).ToList();foreach (var r in result) { double Prob = r.Value("Prob"); }

dynamic version

var result = GraphDB.DB.CreateStatement(Query,perams).ToList();foreach (var r in result) { double Prob = r.Prob; }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ra0o0f/arangoclient.net/issues/113#issuecomment-435871851, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj4Bo8Gf5i6l0VCDgODrAWTZ2-aEmesfks5usDvagaJpZM4YOZyi .