为什么在使用C#中的Neo4j时,’IDriver’不包含’Session’的定义?

huangapple go评论79阅读模式
英文:

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();

huangapple
  • 本文由 发表于 2020年1月4日 00:13:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定