ra0o0f / arangoclient.net

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

How to execute pure AQL queries? #51

Closed PavelPikat closed 7 years ago

PavelPikat commented 8 years ago

I am new to ArangoDB and I find it hard to write complex queries with LINQ, and would like to execute queries in clean AQL. How can it be done within this library?

For example, I want to retrieve all articles that belong to groups current user is member of. My LINQ query looks like

var query = from p in db.Query<Person>()
                where p.Name == "Bob"
                from g in db.Query<Group>()
                from memberOf in db.Query<MEMBER_OF>()
                where memberOf.Person == p.Id
                where g.Id == memberOf.Group
                from a in db.Query<Article>()
                from childOf in db.Query<CHILD_OF>()
                where childOf.Child == a.Id && childOf.Parent == g.Id
                select a;

And my AQL looks like:

FOR u IN People FILTER u.Name == "Bob"
    FOR g IN OUTBOUND u MEMBER_OF
        FOR a IN INBOUND g CHILD_OF RETURN a
kwrang commented 8 years ago

try db.CreateStatement: var articles = db.CreateStatement<Article>("FOR u IN People FILTER u.Name == @name FOR g IN OUTBOUND u MEMBER_OF FOR a IN INBOUND g CHILD_OF RETURN a", new List<QueryParameter>() { new QueryParameter() { Name = "name", Value = "Bob" } }).ToList();

PavelPikat commented 8 years ago

@kwrang Great example! Thank you very much, it works like a charm! :+1:

ra0o0f commented 8 years ago

@PavelPikat i'm planning to add AQL OUTBOUND and INBOUND keywords for LINQ in v3.0 branch this month.

ra0o0f commented 7 years ago

@PavelPikat graph traversal in LINQ is now supported

AQL traversal doc https://docs.arangodb.com/3.0/AQL/Graphs/index.html

LINQ traversal examples https://github.com/ra0o0f/arangoclient.net/blob/next/src/ArangoDB.Client.Examples/Linq/TraversalQuery.cs

see if you can write you query in AQL with new graph traversal syntax