【发布时间】:2021-01-29 22:20:49
【问题描述】:
我有一个返回带有属性的对象列表的查询。考虑一个具有类似结构的 C# 对象:
public class Neo4jResult {
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
}
查询返回一个名为“mycollection”的列,我可以将结果存储到如下内容:
public async Task<IEnumerable<Neo4jResult>> MyNeo4jQuery() {
var cypher = client.Cypher
.Match(matchQuery)
.WithParams(myParams);
cypher =
cypher.ReturnDistinct<Neo4jResult>("mycollection")
.OrderBy("toLower(object.Prop1)");
var query = (IOrderedCypherFluentQuery<Neo4jResult>)cypher;
return await query.ResultsAsync;
}
此代码运行良好。但是,我必须将此记录的计数作为另一个属性,因此我的查询现在返回两列 - “mycollection”和“totalRecords”。为了促进这一点,我创建了一个反映这一点的新对象:
public class Neo4jResultNew {
public int TotalRecords { get; set; }
public IEnumerable<Neo4jResult> Results { get; set; }
}
然后我将我的 neo4j 查询更改为:
public async Task<IEnumerable<Neo4jResult>> MyComplexNeo4jQuery() {
var cypher = client.Cypher
.Match(matchQuery)
.WithParams(myParams);
cypher =
cypher.Return<Neo4jResultNew>( (mycollection, totalRecords) => {
{
Results = mycollection.As<IEnumerable<Neo4jResult>>(),
TotalRecords = totalRecords.As<int>()
});
var query = (IOrderedCypherFluentQuery<Neo4jResultNew>)cypher;
return await query.ResultsAsync;
}
neo4j 返回的错误是:“Neo4j 返回了一个有效的响应,但是 Neo4jClient 无法反序列化为您提供的对象结构”。我只是按照在线示例进行操作,但我的投影中可能缺少一些东西?
【问题讨论】:
标签: c# neo4j neo4jclient