CSharp: Neo4j .NET Driver Manual

凸显出数据的4V(Vlume 大量、Velocity 高速、Variety 多样、Value 价值)特性。

 

(1)键值存储(Key-Value)数据库

主要采用哈希表技术,存储特定的键和指向特定的数据指针。该模型简单、易于部署例如:Redis、Memcached、Riak KV、Hazelcast、Ehcache、Voldemort、Oracle BDB 等。

(2)文档型数据库

以嵌入式版本化文档为数据模型,其灵感是来自于LotusNotes办公软件,支持全文检CouchDB、索、关键字查询等功能。例如:MongoDB、AmazonDynamoDB、Couchbase、SequoiaDB 等。

(3)列存储数据库

列存储数据库是指数据存储采用列式存储架构,相比传统的行式存储架构,数据访问速度更快,压缩率更高,支持大规模横向扩展。例如:Cassandra、HBase、Riak、GBase8a等

(4)图(Graph)数据库

以图论为理论根基,用节点和关系所组成的图为真实世界直观建模,支持百亿乃至千亿量级规模的巨型图的高效关系运算和复杂关系分析,例如:Neo4i、OrientDB、Titan等。

上述四类NSOL数据依据其数据模型的不同,均表现出各自的优势和劣势,以及适应的典型应用场景。

NOSQL 数据库的四大分类分析

分类

数据模型

优势

劣势

典型应用场景

键值数据库

哈希表

查找速度快

数据无结构化,通常只被当作字符串或者二进制数据

内容缓存,主要用于处理大量数据的高访问负载,也用于一些日志系统等

列存储数据库

列式数据存储架构

查找速度快,布横向扩展,数据压缩率高

功能相对受限

分布式文件系统

文档型数据库

键值对扩展

数据结构要求不严格,表结构可变,不需要预先定义表结构

查询性能不高,缺乏统一的查询语法

web 应用

图数据库

节点和关系组成的图

利用图结构相关算法。比如最短路径,节点度关系查找等

可能需要对整个图做计算,不利于图数据分布存储

社交网络、推荐系统、意向图、消费图、兴趣图、关系图谱等

 

各类数据库主要指标分析

分类

            性能

可扩展性

灵活性

复杂性

功能性

键值数据库

可变

列存储数据库

一般

很少

文档型数据库

可变(高)

可变(低)

图数据库

可变

可变

图论

关系数据库

可变

可变

一般

关系代数

 

 

 

MacOS 10.10 (Yosemite)+, Windows 8.1+ with Powershell 5.0+, Ubuntu 12.04+, Fedora 21, Debian 8.

使用D3.js或ECharts等JavaScript库,将Neo4j图数据库中的数据可视化展示在前端页面上

sql: 

1
MATCH (p:Person) RETURN p.name AS name

  

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/// <summary>
/// http://localhost:7474/browser/
/// D:\neo4j\neo4j-community-5.26.0\bin>neo4j.bat console
/// geovindu,Geovin Du
/// </summary>
public class NodeResult
{
    public string title { get; set; }
    public string label { get; set; }
}
 
public class Movie
{
    public string title { get; set; }
    public int released { get; set; }
    public string tagline { get; set; }
}
 
public class Person
{
    public string Name { get; set; } = "";
 
}
 
 
/// <summary>
/// https://github.com/neo4j/neo4j-dotnet-driver
///https://github.com/neo4j-examples/movies-dotnetcore-bolt
///https://github.com/neo4j-examples/movies-dotnet-bolt
///https://neo4j.com/docs/dotnet-manual/current/session-api/
/// </summary>
public class Neo4jHelper
{
 
    /// <summary>
    ///
    /// </summary>
    private IDriver _driver;
    /// <summary>
    ///
    /// </summary>
    /// <param name="uri"></param>
    /// <param name="user"></param>
    /// <param name="password"></param>
    public Neo4jHelper(string uri, string user, string password)
    {
 
 
        _driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
    }
    /// <summary>
    ///
    /// </summary>
    public void close()
    {
        _driver.CloseAsync();
        _driver.Dispose();
 
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public async Task PrintGreetingAsync(string message)
    {
        var session = _driver.AsyncSession();
        var greeting = await session.ExecuteWriteAsync(
            async tx =>
            {
                var result = await tx.RunAsync(
                    "CREATE (a:Greeting) " +
                    "SET a.message = $message " +
                    "RETURN a.message + ', from node ' + id(a)",
                    new { message });
 
                var record = await result.SingleAsync();
                return record[0].As<string>();
            });
 
        Console.WriteLine(greeting);
    }
    /// <summary>
    /// 查询
    /// </summary>
    /// <returns></returns>
    public async Task<List<IRecord>> getQuery()
    {
 
 
        List<IRecord> record = new List<IRecord>();
        //var data= _driver.ExecutableQuery("MATCH (p:Person) RETURN p.name AS name");
        var session = _driver.AsyncSession();
 
        //var exeResult = session.ExecuteWriteAsync(async x =>
        //{
        //    var result = await x.RunAsync("MATCH (p:Person) RETURN p.name AS name");
        //    return await result.ToListAsync();
        //});
        //await exeResult;
 
        // or:
        // exeResult.Wait();
 
 
        var exeResult = session.ExecuteWriteAsync(async x =>
        {
            var result = await x.RunAsync("MATCH (p:Person) RETURN p.name AS name");
            //return await result.ToListAsync();
            record = await result.ToListAsync();
        });
 
        try
        {
            await exeResult;
        }
        catch (ClientException ex)
        {
            Console.WriteLine(ex);
        }
        return record;
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="limit"></param>
    /// <returns></returns>
    public async Task getQuerylist(int limit = 100)
    {
        //string dbConfig = "";
        //var(result, _, _) = await _driver.ExecutableQuery(query).ExecuteAsync();  //.WithConfig(new QueryConfig(database: "neo4j")).ExecuteAsync()
        // IExecutableQuery<records,summary> a= _driver.ExecutableQuery(query);
        // IExecutableQuery<IRecord, IRecord> aa = ExecutableQuery(string cypher);
 
        // return records;
        //return result;
        var statementText = "MATCH (a:Person)-[:ACTED_IN]->(m:Movie) RETURN m.title as movie, collect(a.name) as cast LIMIT {limit}";
        var statementParameters = new Dictionary<string, object> { { "limit", limit } };
 
        var nodes = new List<NodeResult>();
        var relationships = new List<object>();
        // _driver.AsyncSession();
 
         
        using (var session = _driver.AsyncSession())
        {
            var result = await session.RunAsync(statementText, statementParameters);
            var i = 0;
            var records= await result.ToListAsync();
            foreach (var record in records)
            {
                var target = i;
                nodes.Add(new NodeResult { title = record["movie"].As<string>(), label = "movie" });
                i += 1;
 
                var castMembers = record["cast"].As<List<string>>();
                foreach (var castMember in castMembers)
                {
                    var source = nodes.FindIndex(c => c.title == castMember);
                    if (source == -1)
                    {
                        nodes.Add(new NodeResult { title = castMember, label = "actor" });
                        source = i;
                        i += 1;
                    }
                    relationships.Add(new { source, target });
                }
            }
            //result.ToListAsync();
        }
 
         
 
    }
 
}

  

调用:

1
2
3
4
5
6
7
8
9
Neo4jHelper helper = new Neo4jHelper("bolt://localhost:7687", "neo4j", "geovindu");
var a= await helper.getQuery();
Response.Write(a.Count());
foreach (var record in a)
{
     
    Response.Write(record["name"].ToString()+"<br/>");     
    //Response.Write(record[0].ToString() + "<br/>");
}

  

输出:

 

https://www.codeproject.com/Articles/1066378/Introduction-to-Graph-Databases-using-Neo4J-and-it
https://github.com/neo4j-examples/movies-dotnetcore-bolt
https://github.com/DotNet4Neo4j/MoviesMvcCore
https://github.com/micwan88/d3js-neo4j-example
https://github.com/imclab/d3-neo4j
https://github.com/chizhu/KGQA_HLM
https://github.com/eisman/neo4jd3

https://github.com/nhonvo/clean-architecture-net-8.0
https://github.com/SaraRasoulian/DotNet-WebAPI-Sample
https://github.com/thomasdiggs/Web_API_in_ASP.NET_Core_8
https://github.com/PacktPublishing/Web-API-Development-with-ASP.NET-Core-8
https://github.com/YaraGh22-engs/ASP-.NET-Core-8-API-CRUD-Movies-Example
https://github.com/nhonvo/clean-architecture-net-8.0
https://github.com/dotnet-architecture/eShopOnWeb
https://github.com/FabianGosebrink/ASPNETCore-WebAPI-Sample
https://github.com/Nehanthworld/Asp.Net-Core-Web-API-Tutorial
https://github.com/Apress/Apress-Robust-and-Resilient-APIs-with-ASP.NET-Core-8

posted @   ®Geovin Du Dream Park™  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2023-01-27 CSharp: Sort
2023-01-27 CSharp: Collection
2022-01-27 CSharp: iTextSharp 5.13.2 create pdf
2018-01-27 JqGrid: Add,Edit,Del in asp.net
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示