简体   繁体   English

使用 C# Datastax CassandraCSharpDriver.Graph 获取连接到已知顶点的所有未知顶点

[英]Get all unknown vertices connected to a known vertex with C# Datastax CassandraCSharpDriver.Graph

I'm trying to get all the unknown vertices that are connected to a known vertex by an edge using C# Datastax CassandraCSharpDriver.Graph code.我正在尝试使用 C# Datastax CassandraCSharpDriver.Graph 代码获取通过边连接到已知顶点的所有未知顶点。

This gremlin code correctly returns the list of unknown vertices as well as the target known vertex:此 gremlin 代码正确返回未知顶点列表以及目标已知顶点:

g.V().has("mything","key", "mykey")
.emit()
.repeat(outE("contains").inV()).valueMap(true)

I tried a traversal like this in C# but it doesn't come back, I think the repeat is infinite (or very slow):我在 C# 中尝试过这样的遍历但它没有回来,我认为重复是无限的(或非常慢):

g.V()
.Has("mything", "key", "mykey")
.Emit()
.Repeat(g.V()
.Has("mything", "key", "mykey")
.OutE("contains").InV())

I'm trying a traversal like this in C#, but the compiler won't accept '("query")', so I'm not sure how to put the traversal in the Repeat clause:我正在 C# 中尝试这样的遍历,但编译器不会接受 '("query")',所以我不确定如何将遍历放在 Repeat 子句中:

g.V()
.Has("mything", "key", "mykey")
.As("query").Emit()
.Repeat(("query").OutE("contains").InV())

What's the trick to the Repeat clause?重复子句的技巧是什么? Or is there a better way to get all the unknown vertices connected to a known vertex in C#?或者是否有更好的方法将所有未知顶点连接到 C# 中的已知顶点?

I think you're looking for the anonymous graph traversal class Gremlin.Net.Process.Traversal.__ :我认为您正在寻找匿名图遍历类Gremlin.Net.Process.Traversal.__

var graphResultSet = await session.ExecuteGraphAsync(g.V()
                .Has("mything", "key", "mykey").Emit()
                .Repeat(__.OutE("contains").InV())).ConfigureAwait(false);

I've ran a simple code snippet with this query (shown below) and I get this console output:我用这个查询运行了一个简单的代码片段(如下所示),我得到了这个控制台输出:

[label: mything; key: mykey]
[label: mything1; key: mykey15]
[label: mything1; key: mykey12]
[label: mything; key: mykey]
[label: mything1; key: mykey17]
[label: mything1; key: mykey16]
[label: mything1; key: mykey14]
[label: mything1; key: mykey13]
[label: mything1; key: mykey1]

Code snippet:代码片段:

        session.ExecuteGraph(new SimpleGraphStatement(
            "schema.propertyKey('key').Text().ifNotExists().create();" +
            "schema.edgeLabel('contains').multiple().ifNotExists().create();" +
            "schema.vertexLabel('mything').properties('key').ifNotExists().create();" +
            "schema.vertexLabel('mything1').properties('key').ifNotExists().create();" + 
            "schema.edgeLabel('contains').connection('mything', 'mything1').add();"));

        var g = DseGraph.Traversal(session);

        await session.ExecuteGraphAsync(g
                .AddV("mything").Property("key", "mykey").As("cp")
                .AddV("mything").Property("key", "mykey").As("cp1")
                .AddV("mything1").Property("key", "mykey1").As("cl")
                .AddV("mything1").Property("key", "mykey12").As("cl1")
                .AddV("mything1").Property("key", "mykey13").As("cl2")
                .AddV("mything1").Property("key", "mykey14").As("cl3")
                .AddV("mything1").Property("key", "mykey15").As("cl4")
                .AddV("mything1").Property("key", "mykey16").As("cl5")
                .AddV("mything1").Property("key", "mykey17").As("cl6")
                .AddE("contains").From("cp").To("cl")
                .AddE("contains").From("cp1").To("cl1")
                .AddE("contains").From("cp").To("cl2")
                .AddE("contains").From("cp").To("cl3")
                .AddE("contains").From("cp1").To("cl4")
                .AddE("contains").From("cp").To("cl5")
                .AddE("contains").From("cp").To("cl6"))
            .ConfigureAwait(false);

        var graphResultSet = await session.ExecuteGraphAsync(g.V()
            .Has("mything", "key", "mykey").Emit()
            .Repeat(__.OutE("contains").InV())).ConfigureAwait(false);

        var vertices = graphResultSet.Select(elem => elem.To<Vertex>()).ToList();

        Console.WriteLine(
            string.Join(
                Environment.NewLine,
                vertices.Select(v => $"[label: {v.Label}; key: {v.GetProperty("key").Value}]")));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 向 Datastax CassandraCSharpDriver.Graph 中的现有顶点添加新顶点和边,但出现边输出错误 - Adding a new vertex and an edge to an existing vertex in Datastax CassandraCSharpDriver.Graph but get edge OUT error 在 CassandraCSharpDriver.Graph 中使用 SimpleGraphStatement 的树查询抛出“无法转换为 org.apache.tinkerpop.gremlin.structure.Element” - Tree query using SimpleGraphStatement in CassandraCSharpDriver.Graph throws “cannot cast to org.apache.tinkerpop.gremlin.structure.Element” 如何防止已知和未知的机器人C# - How to prevent known and unknown bots c# 无法连接到DataStax Enterprise Graph Db C#驱动程序 - Can not connect to DataStax Enterprise Graph Db C# Driver 在C#中获取连接到WLAN路由器的所有设备的MAC地址 - Get MAC address of all devices connected to WLAN router in C# 检查图上的 2 个节点是否递归连接 C# - Checking if 2 nodes on a graph are connected recursively C# 使用C#通用方法进行数学运算(已知未知) - Doing math in C# generic method (known with unknown) MS Graph SDK C#-获取计划中的所有任务 - MS Graph SDK C# - Get all Tasks within a Plan 如何在 MS Graph C# 中获取所有团队? - How do I get all Teams in MS Graph C#? "在 c# 中使用 Microsoft Graph API 获取所有电子邮件" - Get all email message using Microsoft Graph API in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM