Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

database - How do I connect with Gremlin in dot Net?

I am studying gremlin. I need to connect gremlin to .net and below is my code:

internal class Program
{
    private const string Host = "localhost";
    private const int Port = 8182;
    private const string NameTraversalSource = "gmodern";

    [Obsolete]
    private static void Main(string[] args)
    {
        Console.WriteLine("Start");

        Graph graph = new Graph();

        var client = new GremlinClient(new GremlinServer(Host, Port));

        var g = graph.Traversal().WithRemote(new DriverRemoteConnection(client));

        g.AddV("person").Property("name", "marko");

        var re = g.V().HasLabel("person").Values<string>("name").ToList();
        foreach (var c in re)
        {
            Console.WriteLine(c);
        }

        Console.WriteLine("End");
        Console.ReadKey();
    }
}

I don't know why it doesn't answer the desired result. I added vertex and name property with value of "marko". I need to print it out. But it doesn't print. Why? Help me.

question from:https://stackoverflow.com/questions/65897769/how-do-i-connect-with-gremlin-in-dot-net

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I voted to close this as I thought more details were required, but I think I realize the problem. In many ways the question could be closed as more of a "duplicate" as many Gremlin oriented questions tend to have this answer: You need to iterate your traversal.

The following line does nothing:

g.AddV("person").Property("name", "marko");

All it does is create a traversal (i.e. an Iterator). It does not execute it. To execute you must iterate it with some form of terminal step. Since you are aren't doing anything with the result you should probably use iterate() like:

g.AddV("person").Property("name", "marko").iterate();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...