Convert neo4j list of integers to C# array

0

I have a small C# application that queries a Neo4j database. The queries work fine, but I'm having trouble converting arrays of integers to an appropriate C# list type. It just seems that they should be in a proper List/Array/etc. on the C# side.

Here is the query that I run - it returns the correct results, but I'm not smart enough to get the returned list portion into a proper C# list-type object. Here is the code that is running:

using (var driver = GraphDatabase.Driver("bolt:validURL, AuthTokens.Basic("username", "password")))
//  using (var session = driver.Session())
{
    var result = session.Run("MATCH (c:Climate) WHERE c.koppen = 'BSh' RETURN c.koppen AS koppen, c.counties AS counties");

            foreach (var record in result)
            {
                var koppen = record["koppen"].As<string>();
                var counties = record["counties"];
            }
        }
    }
}

}

The record[counties] is a list of a integers with - so it seems that I should easily be able to put it into a C# list object that I can iterate through. I need to do that in order to process each county and display results. C# is pretty new for me, so thanks for your help in letting me connect these two languages!

EDIT: No responses, so I tried a new approach - to simplify things, I am no longer returning the koppen value - just the list of counties (which is where the problem lies). I found some code in the Neo4j manual, and tried it:

public List<int> GetCounties()
    {
        using (var driver = GraphDatabase.Driver("bolt://validURL", AuthTokens.Basic("username", "password")))
        using (var session = driver.Session())
        {
            return session.ReadTransaction(tx =>
            {
                var result = tx.Run("MATCH (c:Climate) WHERE c.koppen = 'BSh' RETURN c.counties");
                var a = result.Select(Record => Record[0].As<int>()).ToList();
                return a;
            });
        }
    }
}

Now I'm getting an exception: System.InvalidCastException occurred HResult=0x80004002 Message=Unable to cast object of type 'System.Collections.Generic.List`1[System.Object]' to type 'System.IConvertible'. Source= StackTrace:

The exception occurs on the line ending with the toList() statement. Sorry for my not understanding the conversions that need to occur between Neo4j list results and C# lists/arrays/etc. I'm happy to try any suggestions that I get!

c#
arrays
list
neo4j
asked on Stack Overflow Oct 6, 2017 by Jeff Roloff • edited Oct 11, 2017 by Jeff Roloff

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0