DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Why SQL Isn’t the Right Fit for Graph Databases
  • Graph-Oriented Solutions Enhancing Flexibility Over Mutant Requirements
  • How Graph Databases Fight Organized Crime
  • Distribution and Partitioning in Graph Databases

Trending

  • My LLM Journey as a Software Engineer Exploring a New Domain
  • The 4 R’s of Pipeline Reliability: Designing Data Systems That Last
  • The Modern Data Stack Is Overrated — Here’s What Works
  • Rethinking Recruitment: A Journey Through Hiring Practices
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Build Your First .NET Graph Database

How to Build Your First .NET Graph Database

By 
Damaris Coll user avatar
Damaris Coll
·
Mar. 13, 13 · Interview
Likes (0)
Comment
Save
Tweet
Share
14.4K Views

Join the DZone community and get the full member experience.

Join For Free

There has been a lot of talking about NoSQL lately, and how this "new" databases can solve problems of Big Data. NoSQL is a movement that promotes alternatives to the relational model in order to provide higher scalability and availability using simple and lightweight systems of storage and retrieval.

As part of the NoSQL movement, Graph Databases in particular are especially suited for applications that need to analyze relationships in a network of data assuring high scalability. They are also suited to deal with ad-hoc data or including different type of data as they are less rigid with the schema. 

Among the most well-known databases there are solutions specially for .Net developers, for instance DEX graph database offers full support for their native C# API with direct and fast access to the graph core, popular Neo4j offers third-party .NET client via REST API, Microsoft research Trinity also supports C# language (although it is more a key-value solution) and CloudGraph seems to focus also on .Net with a beta-release.

So, for all .Net developers that are interested into using graphs for their applications, this article will give them a first hint of how to construct a first graph in C# using Visual Studio. For the example we are going to use DEX's native .Net API for a simple first approach.

  1. Download your API (in this case DEX API can be downloaded from here )
  2. Create the C# console application
  3. Replace the Program.cs with the sample below.  This is a typical HelloWorld example where the developer will create a graph database with two nodes (of the same type) and an edge between them. Nodes and edges are the main units of a graph (graph theory ), nodes can be seen as a row of a relational table whereas edges could be seen as the foreign key relating two rows from different tables. The example also includes a neighbors operation, in order to see how information is retrieved from a graph database. Following the relational simile, this retrieval from the graph would be like a select operation from the rows of the two tables joined by the foreign key.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using com.sparsity.dex.gdb;
    
    namespace HelloWorld
    {
        class Program
        {
            static void Main(string[] args)
            {
                //
                // Create a sample database
                //
                DexConfig cfg = new DexConfig();
                Dex dex = new Dex(cfg);
                Database db = dex.Create("HelloWorld.dex", "HelloWorld");
                Session sess = db.NewSession();
                Graph g = sess.GetGraph();
    
                // Add a node type with two attributes
                int nodeType = g.NewNodeType("TheNodeType");
                int idAttribute = g.NewAttribute(nodeType, "id", DataType.Long, AttributeKind.Unique);
                int nameAttribute = g.NewAttribute(nodeType, "name", DataType.String, AttributeKind.Indexed);
    
                // Add a directed edge type with an attribute
                int edgeType = g.NewEdgeType("TheEdgeType", true, false);
    
                // Add a node
                long hellow = g.NewNode(nodeType);
                Value value = new Value();
                g.SetAttribute(hellow, idAttribute, value.SetLong(1));
                g.SetAttribute(hellow, nameAttribute, value.SetString("Hellow"));
    
                // Add another node
                long world = g.NewNode(nodeType);
                g.SetAttribute(world, idAttribute, value.SetLong(2));
                g.SetAttribute(world, nameAttribute, value.SetString("World"));
    
                // Add an edge
                long theEdge = g.NewEdge(edgeType, hellow, world);
    
                // Get the neighbors of the first node using the edges of "TheEdgeType" type
                Objects neighbors = g.Neighbors(hellow, edgeType, EdgesDirection.Outgoing);
    
                // Say hello to the neighbors
                ObjectsIterator it = neighbors.Iterator();
                while (it.HasNext())
                {
                    long neighborOid = it.Next();
                    g.GetAttribute(neighborOid, edgeType, value);
                    System.Console.WriteLine("Hello " + value.GetString());
                }
                // The ObjectsIterator must be closed
                it.Close();
                // The Objects must be closed
                neighbors.Close();
    
                // Close the database
                sess.Close();
                db.Close();
                dex.Close();
            }
        }
    }
  4. Add a reference in the project (Menu Project -> AddReference) to the library "dexnet.dll".
  5. Put the other dlls in a directory where the application can found it. The easier way is to put them where the application exe is created. Or set the working directory to the directory where you have the dlls. But you could also put them with the windows dlls.
  6. Here it is your first .Net graph!
  7. What next? populate your graph database with more nodes and edges (play with different types of nodes and edges!) and also do not forget to use popular graph algorithms (take a look at this dzone article here or this more advanced here )


Relational database Database Graph (Unix) Build (game engine)

Opinions expressed by DZone contributors are their own.

Related

  • Why SQL Isn’t the Right Fit for Graph Databases
  • Graph-Oriented Solutions Enhancing Flexibility Over Mutant Requirements
  • How Graph Databases Fight Organized Crime
  • Distribution and Partitioning in Graph Databases

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: