Giter VIP home page Giter VIP logo

Comments (11)

ra0o0f avatar ra0o0f commented on May 31, 2024

@JulianMay if you want to know your options to how model your data and its relations in ArangoDB, there is a blog post by them in detail with samples

http://radar.oreilly.com/2015/07/data-modeling-with-multi-model-databases.html

but for a simple answer:

public class Target
    {
        [DocumentProperty(Identifier = IdentifierType.Key)]
        public string Key;

        [DocumentProperty(Identifier = IdentifierType.Handle)]
        public string Id;

        public string Content;
    }

    public class TargetRelation
    {
        [DocumentProperty(Identifier = IdentifierType.Key)]
        public string Key;

        [DocumentProperty(Identifier = IdentifierType.EdgeFrom)]
        public string From;

        [DocumentProperty(Identifier = IdentifierType.EdgeTo)]
        public string To;
    }                


                var firstTarget = new Target { Content = "firstTarget" };
                var secondTarget = new Target { Content = "secondTarget" };
                var thirdTarget = new Target { Content = "thirdTarget" };

                db.Insert<Target>(firstTarget);
                db.Insert<Target>(secondTarget);
                db.Insert<Target>(thirdTarget);

                TargetRelation relationWithSecond = new TargetRelation();
                db.InsertEdge<TargetRelation>(firstTarget.Id, secondTarget.Id, relationWithSecond);

                TargetRelation relationWithThird = new TargetRelation();
                db.InsertEdge<TargetRelation>(firstTarget.Id, thirdTarget.Id, relationWithThird);


                var relations = db.Edges<TargetRelation>(firstTarget.Id, EdgeDirection.Outbound);

                var count = relations.Select(r => r.To).Except(new string[] { secondTarget.Id, thirdTarget.Id }).Count();

                Debug.Assert(count == 0);

also client now does not support ArangoDB General Graph operations for now, it will be in the client by tommarow

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 31, 2024

@JulianMay you can also use LINQ(aql query) for this

var relationsCount = db.Query()
                    .For(_ => AQL.Edges<TargetRelation>(firstTarget.Id, EdgeDirection.Outbound)
                    .Where(r => AQL.In(r.To, new string[] { secondTarget.Id, thirdTarget.Id })))
                    .Count();

                // which translates to:
                // return length ((
                // for `r` in  edges(  `TargetRelation` , "Target/7433562403", 'outbound')
                // filter  `r`.`_to`  in  ["Target/7433759011", "Target/7433955619"]
                // return  `r` ))

                Debug.Assert(relationsCount == 2);

from arangoclient.net.

JulianMay avatar JulianMay commented on May 31, 2024

Thank you so much!

Just a note: wouldnt you be writing an evergreen here? (Empty result would assert as well as expected result)

var count = relations.Select(r => r.To).Except(new string[] { secondTarget.Id, thirdTarget.Id }).Count();
Debug.Assert(count == 0);

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 31, 2024

@JulianMay you are right switch the comparison, i said to myself you would debug it to see how it works

from arangoclient.net.

JulianMay avatar JulianMay commented on May 31, 2024

Works like a charm - thanks again

from arangoclient.net.

JulianMay avatar JulianMay commented on May 31, 2024

Just for my understanding: Is is correctly understood that the following traversal problem will be solvable with arrangoclient.net once the general graph operations are implemented?

With this model:

"targetB" --[isPartOf]-->"targetA"
"targetC" --[isPartOf]-->"targetB"
"note1" --[attachedTo]-->"targetB"
"note2" --[attachedTo]-->"targetA"
"note3" --[attachedTo]-->"targetC"

I'll be able to traverse the graph from "targetA" and return all 3 notes?

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 31, 2024

@JulianMay you could do this with this version, without need for creating graph with General graph api

var firstTarget = new Target { Content = "firstTarget" };
                var secondTarget = new Target { Content = "secondTarget" };
                var thirdTarget = new Target { Content = "thirdTarget" };

                db.Insert<Target>(firstTarget);
                db.Insert<Target>(secondTarget);
                db.Insert<Target>(thirdTarget);

                TargetRelation firstWithSecond = new TargetRelation();
                db.InsertEdge<TargetRelation>(firstTarget.Id, secondTarget.Id, firstWithSecond);

                TargetRelation secondWithThird = new TargetRelation();
                db.InsertEdge<TargetRelation>(secondTarget.Id, thirdTarget.Id, secondWithThird);


                var vertexes = db.Query()
                    .For(_ => AQL.Traversal<Target, TargetRelation>(firstTarget.Id, EdgeDirection.Outbound))
                    .ToList();

look at the traversal api ()

https://docs.arangodb.com/Aql/GraphFunctions.html

as far as i know General graphs let you define a graph across several edge collections and guarantees like removing vertex and its connected edges transitionally.

i did not dig deep in to General graphs to know where to create graph or not. how about ask it on stackoverflow to get best answer? tag it with .net so i can write how to do it in .net client

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 31, 2024

also note that for graph operations and general graph operations, i am working to support all operations and release a new version in incoming days.

from arangoclient.net.

JulianMay avatar JulianMay commented on May 31, 2024

Thanks again - This is awesome

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 31, 2024

@JulianMay client now supports all graph operations

from arangoclient.net.

JulianMay avatar JulianMay commented on May 31, 2024

Awesome :)

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.