Giter VIP home page Giter VIP logo

Comments (8)

drgraduss avatar drgraduss commented on May 31, 2024

Example queries below:

FOR id IN GRAPH_NEIGHBORS('Test', 'doc/id', {direction:'outbound', maxDepth:1, edgeExamples:[{attr:'value'}]})
FOR u IN User
FILTER u._id == id
RETURN u

Instead below:

FOR id IN GRAPH_NEIGHBORS('Test', 'doc/id', {direction:'outbound', maxDepth:1, edgeExamples:[{attr:'value'}]})
RETURN document(id)

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 31, 2024

@drgraduss aql has Document function you can look it at Miscellaneous functions, unfortunately i didn't add Miscellaneous functions yet, but you can add them with the following code:

this is how you can add custom AQL functions too:

    public class CustomAQL
    {
        [UserFunction(Name = "document")]
        public static T Document<T>(string id)
        {
            throw new Exception("use custom AQL functions inside linq queries");
        }

        [UserFunction(Name = "document")]
        public static IList<T> Document<T>(IList<string> ids)
        {
            throw new Exception("use custom AQL functions inside linq queries");
        }
    }

    // and use them like:

    var query1 = db.Query().Select(_ => CustomAQL.Document<Person>("Person/123"));

    // output: return document("Person/123")
    Console.WriteLine(query1.GetQueryData().QueryReplacedWithVariables(db));

    var query2 = db.Query().Select(_ => CustomAQL.Document<Person>(new string[] { "Person/123" }));

    // output: return document(  ["Person/123"]  )
    Console.WriteLine(query2.GetQueryData().QueryReplacedWithVariables(db));

i will add Miscellaneous functions in next release

from arangoclient.net.

drgraduss avatar drgraduss commented on May 31, 2024

A bit of context. Consider query below:

db.Query().For(x => 
  AQL.GraphNeighbors<Vertex>(
    "graph-name",
    new { _key = "vertex-key" },
    new
    {
      direction = EdgeDirection.Outbound,
      maxDepth = 1,
      edgeExamples = new[] { new { attr = "edge-attr-filter" } }
    }));

This query will throw ArangoDB.Client.Common.Newtonsoft.Json.JsonSerializationException: cannot convert value 'string' to type 'Vertex'. Using AQL.GraphNeighbors<Vertex>() and AQL.GraphNeighbors<string> will produce the same query:

for generated_0in graph_neighbors( @P1 , @P2 , @P3 ) returngenerated_0``

which works in the second example.

If you change query to
for generated_0 in graph_neighbors( @P1 , @P2 , @P3 ) return document(generated_0)
(by adding document function) query works in first example as well.

That was my original issue. Sorry for being a bit long.

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 31, 2024

@drgraduss i'm not deep into graphs but if you look at the method signature:

public static IList<TVertexResult> GraphNeighbors<TVertexResult>(string graphName, object vertexExample, object options)

the reason that i named the generic parameter TVertexResult is for includeData option parameter which if set to true result will be full documents instead of their ids. this may solve your problem

otherwise you can still write it like below, but includeData would give you more performance(at least i think)

var query = db.Query().For(_ =>
  AQL.GraphNeighbors<string>(
    "graph-name",
    new { _key = "vertex-key" },
    new
    {
        direction = EdgeDirection.Outbound,
        maxDepth = 1,
        edgeExamples = new[] { new { attr = "edge-attr-filter" } }
    })
    .Select(id=> CustomAQL.Document<Vertex>(id)));

from arangoclient.net.

drgraduss avatar drgraduss commented on May 31, 2024

Thanks a lot, @ra0o0f. I completely missed includeData option. CustomAQL works as well,
but I will stick with includeData. It's just not obvious when it's legal to use document type as TVertexResult and not a string.

Thanks for your help!

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 31, 2024

@drgraduss you are right, there should be document for all of this but i can't provide it until next month. but the API is so much similar to the internal javascript API at the ArangoDB website, i hope it can help until i provide one

from arangoclient.net.

drgraduss avatar drgraduss commented on May 31, 2024

@ra0o0f Not a problem at all. Trial and error works best as usual :)

from arangoclient.net.

tonys1110 avatar tonys1110 commented on May 31, 2024

The attached patch allows db.Document(id) to be used in LINQ statements. For example:

from user in db.Query<User>()
let dept = db.Document<Department>(user.dept_id)
where dept.name == "cars"
select user

This would previously throw an exception like "Method Document not being supported in ArangoLinqProvider."

add-document.diff.txt

from arangoclient.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.