[英]Hello World Example For Official Neo4J Driver Is Having A Reference Problem When Calling Session
Ok,好的,
I'm in C# using .NET Framework 4.7.2.我在 C# 中使用 .NET 框架 4.7.2。 I'm trying to use the Hello World example https://neo4j.com/developer/dotnet/ .
我正在尝试使用 Hello World 示例https://neo4j.com/developer/dotnet/ 。 I've installed the driver w/ "PM Install-Package Neo4j.Driver-4.0" and have a reference in the project for version 4.0.78.1.
我已经安装了带有“PM Install-Package Neo4j.Driver-4.0”的驱动程序,并在项目中提供了版本 4.0.78.1 的参考。
For the line对于线路
using (var session = _driver.Session())
I'm getting我越来越
'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?)
“IDriver”不包含“Session”的定义,并且找不到接受“IDriver”类型的第一个参数的可访问扩展方法“Session”(您是否缺少 using 指令或程序集引用?)
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");
}
}
}
}
Clearly I'm missing something simple - but after two hours of searching I'm out of ideas.显然我错过了一些简单的东西 - 但经过两个小时的搜索,我已经没有想法了。
For Driver version 4, you need to add Neo4j.Driver.Simple
Nuget package to the project as well.对于驱动程序版本 4,您还需要将
Neo4j.Driver.Simple
Nuget package 添加到项目中。 Either via graphic interface, or via command line as PM> Install-Package Neo4j.Driver.Simple
通过图形界面或通过命令行作为
PM> Install-Package Neo4j.Driver.Simple
According to Neo4j Driver 4.0 docs, Session()
is an extension on IDriver
interface.根据Neo4j Driver 4.0文档,
Session()
是IDriver
接口的扩展。 And as per Session() doc, it's from:根据Session()文档,它来自:
Assembly: Neo4j.Driver.Simple (in Neo4j.Driver.Simple.dll) Version: 4.0.2
组件: Neo4j.Driver.Simple (在 Neo4j.Driver.Simple.dll 中)版本:4.0.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.