Neo4j-如何使用 C# 客户端密码使用 WITH 子句
Neo4j- how to use WITH clause using c# client cypher
我正在尝试在 C# neo4j 客户端中使用 WITH 子句获取结果。
由于我是 neo4j 的新手,所以我不知道如何在 C# 中获得结果。
请帮助我提出你的建议
MATCH (cs:CrawlerInfo)
WITH cs, SIZE((cs)-[:CONTAINS]->()) as TotalResult
RETURN
cs.CrawlerName,cs.Keyword,cs.SearchType,toint(TotalResult),cs.CrawlerInfoDate
order by toint(cs.CrawlerId) desc
在 Neo4jClient
中直接翻译是关键,应该可以通过 API 找到。
//gc = GraphClient instance
//CrawlerInfo is a class
gc.Cypher
.Match("(cs:CrawlerInfo)")
.With("cs, SIZE( (cs)-[:CONTAINS]->() ) as TotalResult")
.Return((cs, TotalResult) => new
{
CrawlerName = cs.As<CrawlerInfo>().CrawlerName,
Keyword = cs.As<CrawlerInfo>().Keyword,
SearchType = cs.As<CrawlerInfo>().SearchType,
CrawlerInfoDate = cs.As<CrawlerInfo>().CrawlerInfoDate,
Size = Return.As<int>("toint(TotalResult)")
})
.OrderByDescending("toint(cs.CrawlerId)");
就个人而言,我会让我的 CrawlerInfo
class 看起来像:
public class CrawlerInfo
{
public int CrawlerId { get; set;}
public string CrawlerName { get; set; }
public string Keyword { get; set; }
public string SearchType { get; set; }
public string CrawlerInfoDate { get; set;}
}
那么你也不需要/(不应该!)需要做 toint
,这意味着你可以做:
gc.Cypher
.Match("(cs:CrawlerInfo)")
.With("cs, SIZE( (cs)-[:CONTAINS]->() ) as TotalResult")
.Return((cs, TotalResult) => new
{
CrawlerName = cs.As<CrawlerInfo>().CrawlerName,
Keyword = cs.As<CrawlerInfo>().Keyword,
SearchType = cs.As<CrawlerInfo>().SearchType,
CrawlerInfoDate = cs.As<CrawlerInfo>().CrawlerInfoDate,
Size = Return.As<int>("TotalResult")
})
.OrderByDescending("cs.CrawlerId");
这有点整洁。我也很想只 return CrawlerInfo
对象本身,而不是属性(或者如果 CrawlerInfo
很大,则制作一个小的 CrawlerInfoLite
模型):
gc.Cypher
.Match("(cs:CrawlerInfo)")
.With("cs, SIZE((cs)-[:CONTAINS]->()) as TotalResult")
.Return((cs, TotalResult) => new
{
CrawlerInfo = cs.As<CrawlerInfo>(),
Size = Return.As<int>("TotalResult")
})
.OrderByDescending("cs.CrawlerId");
其中 CrawlerInfo
定义为:
public class CrawlerInfo
{
public int CrawlerId { get; set;}
public string CrawlerName { get; set; }
public string Keyword { get; set; }
public string SearchType { get; set; }
public string CrawlerInfoDate { get; set;}
}
我正在尝试在 C# neo4j 客户端中使用 WITH 子句获取结果。
由于我是 neo4j 的新手,所以我不知道如何在 C# 中获得结果。
请帮助我提出你的建议
MATCH (cs:CrawlerInfo)
WITH cs, SIZE((cs)-[:CONTAINS]->()) as TotalResult
RETURN
cs.CrawlerName,cs.Keyword,cs.SearchType,toint(TotalResult),cs.CrawlerInfoDate
order by toint(cs.CrawlerId) desc
在 Neo4jClient
中直接翻译是关键,应该可以通过 API 找到。
//gc = GraphClient instance
//CrawlerInfo is a class
gc.Cypher
.Match("(cs:CrawlerInfo)")
.With("cs, SIZE( (cs)-[:CONTAINS]->() ) as TotalResult")
.Return((cs, TotalResult) => new
{
CrawlerName = cs.As<CrawlerInfo>().CrawlerName,
Keyword = cs.As<CrawlerInfo>().Keyword,
SearchType = cs.As<CrawlerInfo>().SearchType,
CrawlerInfoDate = cs.As<CrawlerInfo>().CrawlerInfoDate,
Size = Return.As<int>("toint(TotalResult)")
})
.OrderByDescending("toint(cs.CrawlerId)");
就个人而言,我会让我的 CrawlerInfo
class 看起来像:
public class CrawlerInfo
{
public int CrawlerId { get; set;}
public string CrawlerName { get; set; }
public string Keyword { get; set; }
public string SearchType { get; set; }
public string CrawlerInfoDate { get; set;}
}
那么你也不需要/(不应该!)需要做 toint
,这意味着你可以做:
gc.Cypher
.Match("(cs:CrawlerInfo)")
.With("cs, SIZE( (cs)-[:CONTAINS]->() ) as TotalResult")
.Return((cs, TotalResult) => new
{
CrawlerName = cs.As<CrawlerInfo>().CrawlerName,
Keyword = cs.As<CrawlerInfo>().Keyword,
SearchType = cs.As<CrawlerInfo>().SearchType,
CrawlerInfoDate = cs.As<CrawlerInfo>().CrawlerInfoDate,
Size = Return.As<int>("TotalResult")
})
.OrderByDescending("cs.CrawlerId");
这有点整洁。我也很想只 return CrawlerInfo
对象本身,而不是属性(或者如果 CrawlerInfo
很大,则制作一个小的 CrawlerInfoLite
模型):
gc.Cypher
.Match("(cs:CrawlerInfo)")
.With("cs, SIZE((cs)-[:CONTAINS]->()) as TotalResult")
.Return((cs, TotalResult) => new
{
CrawlerInfo = cs.As<CrawlerInfo>(),
Size = Return.As<int>("TotalResult")
})
.OrderByDescending("cs.CrawlerId");
其中 CrawlerInfo
定义为:
public class CrawlerInfo
{
public int CrawlerId { get; set;}
public string CrawlerName { get; set; }
public string Keyword { get; set; }
public string SearchType { get; set; }
public string CrawlerInfoDate { get; set;}
}