英文:
Why does 'IDriver' not contain a definition for 'Session' when using Neo4j in C#?
问题
I'm following this guide here to help me get started in writing a simple query to retrieve some nodes I have established in a local database.
The NuGet package I'm using says 4.0.0, and the documentation is 1.7. I'm not sure if the 4.0.0 is the server version of Neo4J or the .NET API version.
This block here:
public void GetMedicalDevices () {
string query = "match (n:MedicalDevices) return n";
using (var session = _driver.Session()) {
var data = session.WriteTransaction(tx =>
{
var result = tx.Run( query );
return result;
});
}
}
At _driver.Session()
is where this error is happening I can't figure out.
CS1061 '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?)
I'm not sure what other references I'm missing if any, or if maybe the documentation I'm reading is out of date and Session()
actually doesn't exist on "IDriver" anymore.
Here's the whole class I'm using to write some foobar code to see some things working:
class HelloBoltDriver : IDisposable {
private readonly IDriver _driver;
public HelloBoltDriver (string uri, string user, string password) {
try {
_driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
} catch (Exception e) {
Debug.Log(e.Message);
}
}
public void GetMedicalDevices () {
string query = "match (n:MedicalDevices) return n";
using (var session = _driver.Session()) {
var data = session.WriteTransaction(tx =>
{
var result = tx.Run( query );
return result;
});
}
}
public void Dispose () {
_driver?.Dispose();
}
}
英文:
I'm following this guide here to help me get started in writing a simple query to retrieve some nodes I have established in a local database.
The NuGet package I'm using says 4.0.0, and the documentation is 1.7. I'm not sure if the 4.0.0 is the server version of Neo4J or the .NET API version.
This block here:
public void GetMedicalDevices () {
string query = "match (n:MedicalDevices) return n";
using (var session = _driver.Session()) {
var data = session.WriteTransaction(tx =>
{
var result = tx.Run( query );
return result;
});
}
}
At _driver.Session()
is where this error is happening I can't figure out.
CS1061 '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?)
I'm not sure what other references I'm missing if any, or if maybe the documentation I'm reading is out of data and Session()
actually doesn't exist on "IDriver" anymore.
Here's the whole class I'm using to write some foobar code to see some things working.
class HelloBoltDriver : IDisposable {
private readonly IDriver _driver;
public HelloBoltDriver (string uri, string user, string password) {
try {
_driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
} catch (Exception e) {
Debug.Log(e.Message);
}
}
public void GetMedicalDevices () {
string query = "match (n:MedicalDevices) return n";
using (var session = _driver.Session()) {
var data = session.WriteTransaction(tx =>
{
var result = tx.Run( query );
return result;
});
}
}
public void Dispose () {
_driver?.Dispose();
}
}
答案1
得分: 2
以下是要翻译的内容:
Explanation of Simple Session as an extension to the main driver is here
You need to install the Neo4j.Driver.Simple package
英文:
Explanation of Simple Session as an extension to the main driver is here
You need to install the Neo4j.Driver.Simple package
答案2
得分: 1
以下是翻译好的代码部分:
private async Task mnu_ClickAsync(object sender, RoutedEventArgs e)
{
IDriver driver = GraphDatabase.Driver("neo4j://localhost:7687", AuthTokens.Basic("username", "pasSW0rd"));
IAsyncSession session = driver.AsyncSession(o => o.WithDatabase("neo4j"));
try
{
IResultCursor cursor = await session.RunAsync("CREATE (n) RETURN n");
await cursor.ConsumeAsync();
}
finally
{
await session.CloseAsync();
}
await driver.CloseAsync();
}
英文:
Try to use something like:
private async Task mnu_ClickAsync(object sender, RoutedEventArgs e)
{
IDriver driver = GraphDatabase.Driver("neo4j://localhost:7687", AuthTokens.Basic("username", "pasSW0rd"));
IAsyncSession session = driver.AsyncSession(o => o.WithDatabase("neo4j"));
try
{
IResultCursor cursor = await session.RunAsync("CREATE (n) RETURN n");
await cursor.ConsumeAsync();
}
finally
{
await session.CloseAsync();
}
await driver.CloseAsync();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论