官方 Neo4J 驱动程序的 Hello World 示例在调用会话时出现引用问题

Hello World Example For Official Neo4J Driver Is Having A Reference Problem When Calling Session

好的,

我在 C# 中使用 .NET Framework 4.7.2。我正在尝试使用 Hello World 示例 https://neo4j.com/developer/dotnet/。我已经安装了带 "PM Install-Package Neo4j.Driver-4.0" 的驱动程序,并在项目中引用了版本 4.0.78.1.

对于行

using (var session = _driver.Session())

我正在

'IDriver' does not contain a definition for 'Session' and no accessible extension method 'Session' accepting a first argument of type 'IDriver' could be found (are you missing a using directive or an assembly reference?)

using Neo4j.Driver;
using System;
using System.Linq;
namespace ConsoleApp5 {
    public class HelloWorldExample : IDisposable
    {
        private readonly IDriver _driver;

        public HelloWorldExample(string uri, string user, string password)
        {
            _driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
        }

        public void PrintGreeting(string message)
        {
            using (var session = _driver.Session())
            {
                var greeting = session.WriteTransaction(tx =>
                {
                    var result = tx.Run("CREATE (a:Greeting) " +
                                        "SET a.message = $message " +
                                        "RETURN a.message + ', from node ' + id(a)",
                        new { message });
                    return result.Single()[0].As<string>();
                });
                Console.WriteLine(greeting);
            }
        }

        public void Dispose()
        {
            _driver?.Dispose();
        }

        public static void Main()
        {
            using (var greeter = new HelloWorldExample("bolt://localhost:7687", "neo4j", "password"))
            {
                greeter.PrintGreeting("hello, world");
            }
        }
    }    
    }

很明显,我遗漏了一些简单的东西 - 但经过两个小时的搜索,我没有想法了。

对于驱动程序版本 4,您还需要将 Neo4j.Driver.Simple Nuget 包添加到项目中。通过图形界面,或通过命令行 PM> Install-Package Neo4j.Driver.Simple

根据 Neo4j Driver 4.0 docs, Session() is an extension on IDriver interface. And as per Session() 文档,它来自:

Assembly: Neo4j.Driver.Simple (in Neo4j.Driver.Simple.dll) Version: 4.0.2