Comments (11)
@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.
@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.
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.
@JulianMay you are right switch the comparison, i said to myself you would debug it to see how it works
from arangoclient.net.
Works like a charm - thanks again
from arangoclient.net.
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.
@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.
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.
Thanks again - This is awesome
from arangoclient.net.
@JulianMay client now supports all graph operations
from arangoclient.net.
Awesome :)
from arangoclient.net.
Related Issues (20)
- ArangoServerException not throw when db unavailable HOT 2
- Thread safety HOT 7
- Confused with SystemDatabaseCredential HOT 5
- Custom Index HOT 6
- ByExampleAsync missing HOT 2
- Make ChangeCollectionPropertyForType public HOT 1
- Using LINQ query with Where performance HOT 1
- Error in generated AQL when upserting a generic document HOT 7
- ArangoServerException eats up all the useful information like status code and error number HOT 2
- Make collection name resolver more extensible HOT 2
- Annotating a property of type Guid as DocumentProperty.Key throws InvalidCastException HOT 2
- Support private setter
- CreateStatement<object> & Remove Vertex HOT 1
- Ternary operator support
- Global error handling policy
- Support for keyOptions: uuid
- Edge Document API not supported?
- Cannot Simply Connect to Server...... HOT 2
- Secure connection to ArangoDB
- Query directly within a collection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arangoclient.net.