Gremlinq / ExRam.Gremlinq

A .NET object-graph-mapper for Apache TinkerPop™ Gremlin enabled databases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating Edge if doesn't exist

mike-kolback opened this issue · comments

Trying to replicate the following query in GremlinQ, but having some issues.

g.V().has('person','name','vadas').as('v').
           V().has('software','name','ripple').
           coalesce(__.inE('created').where(outV().as('v')),
                    addE('created').from('v').property('weight',0.5))

What I have currently is

await _g
                .V<T>()
                .Where(sourceVertexExpression)
                .As((__, sourceVertex) => __
                    .V(vertexToLink.Id)
                    .Coalesce(
                        (q) => q.InE<Contains>().Where(),
                        (q) => q.AddE<Contains>().From(sourceVertex)
                    )
                )
                .FirstOrDefaultAsync();

Not sure what to use in the Where to match the out vertex to the step label. Any help would be greatly appreciated.

.where(outV().as('v')) is effectively an identity() step since you're applying it on an edge, which must have an outV() so the where in this case won't ever filter out anything. So I assume the raw Gremlin is already not doing what you're trying to do.

You're probably aiming for .where(outV().where(eq('v')) which is just .Where(__ => __.OutV().Where(x => x == sourceVertex.Value)) in Gremlinq.

Thanks @danielcweber!

So i reworked the query to this

await _g
                .V<T>()
                .Where(sourceVertexEqualityExpression)
                .As((__, sourceVertex) => __
                    .V(vertexToLink.Id)
                    .Coalesce(
                        (q) => q.InE<Contains>().Where(__ => __.OutV().Where(x => x == sourceVertex)),
                        (q) => q.AddE<Contains>().From(sourceVertex)
                    )
                )
                .FirstOrDefaultAsync();

Now im getting an issue where the coalesce is breaking during compile time with the following exception

The type arguments for method 'IGremlinQueryBaseRec<IVertexGremlinQuery<object>>.Coalesce<TTargetQuery>(params Func<IVertexGremlinQuery<object>, TTargetQuery>[])' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Not quite sure what the type arguments should be in this situation.

You need a common type for both the queries that Coalesce takes. One of them is currently probably something like IInEdge.... and the other one just IEdge.... or something. Try the various "Force...." -methods to force them to the lowest common interface ("ForceEdge" will probably do).

Got it working, thanks!