At the end of this guide, you will have created a simple .NET console
Hello, World! program that connects to the Memgraph database and executes simple queries.
For this guide you will need:
- A running Memgraph instance. If you need to set up Memgraph, take a look at the Installation guide.
- A basic understanding of graph databases and the property graph model.
Please note that the code samples in this guide utilize the
Neo4j.Driver.Simple package which implements a blocking interface around the 'main' driver. It should be used as a tool for getting started quickly. The
Neo4j.Driver package contains the official and complete driver for real-world projects.
The driver documentation can be found here: Neo4j .NET Driver.
We'll be using Visual Studio 2019 on Windows 10 to connect a simple .NET console application to a running Memgraph instance.
If you're using a different IDE, the steps might be slightly different, but the code is probably the same or very similar.
Let's jump in and connect a simple program to Memgraph.
1. Open Visual Studio and create a new project.
2. Find and select the Console App (.NET Core) template by using the search box.
3. Name your project MemgraphApp, choose an appropriate location for it, and click Create.
4. Select the Tools > NuGet Package Manager > Package Manager Console menu command.
5. Once the console opens, check that the Default project drop-down list shows the project into which you want to install the package. If you have a single project in the solution, it is already selected.
6. Enter the command Install-Package Neo4j.Driver.Simple.
Now, you should have the newest version of the driver installed and can proceed to copy the following code into the Program.cs file.
Once you run the program, you should see an output similar to the following:
If you want to try out more complex operations, feel free to use the refactored code below.
For real-world examples of how to use Memgraph, we suggest you take a look at the Tutorials page. You can also browse through the Database functionalities section to get an overview of all the functionalities Memgraph offers.
Visit the Getting help page in case you run into any kind of problem or you have additional questions.