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
Please enter at least three characters to search
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

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

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

  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • A Modern Stack for Building Scalable Systems
  • Ensuring Configuration Consistency Across Global Data Centers
  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
Oops! Something Went Wrong

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:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!