Neo4jClient "CASE WHEN" 连同返回
Posted
技术标签:
【中文标题】Neo4jClient "CASE WHEN" 连同返回【英文标题】:Neo4jClient "CASE WHEN" together with return 【发布时间】:2019-12-28 22:07:06 【问题描述】:我正试图弄清楚如何做这样的事情(简化):
RETURN CASE WHEN groups IS NOT NULL THEN collect(groups) ELSE NULL END
在 C# 中使用 Neo4jClient。我试过这个:
.Return((groups) => new
Board = parentBoard.As<Board>(),
Groups = Return.As<Groups>("CASE WHEN groups IS NOT NULL THEN collect(groups) ELSE NULL END")
);
但它会引发异常。我无法找到有关如何使用 neo4jclient 正确执行此操作的任何信息。我这样做的方式似乎确实返回了一个有效的 json 响应,但 neo4jclient 显然无法读取它。因此,我怀疑 neo4jclient 期望以其他方式完成此操作?基本上,如果groups
为null,我想返回null,因为collect(NULL) 不只返回null。有什么想法吗?
System.ArgumentException: Neo4j returned a valid response, however Neo4jClient was unable to deserialize into the object structure you supplied.
First, try and review the exception below to work out what broke.
If it's not obvious, you can ask for help at http://***.com/questions/tagged/neo4jclient
Include the full text of this exception, including this message, the stack trace, and all of the inner exception details.
Include the full type definition of <>f__AnonymousType2`2[[Kolan.Models.Board, Kolan, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Kolan.Models.Groups, Kolan, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
Include this raw JSON, with any sensitive values replaced with non-sensitive equivalents:
"columns":["Board","Groups"],"data":[["extensions":,"metadata":"id":370,"labels":["Board"],"paged_traverse":"http://localhost:7474/db/data/node/370/paged/traverse/returnType?pageSize,leaseTime","outgoing_relationships":"http://localhost:7474/db/data/node/370/relationshi
ps/out","outgoing_typed_relationships":"http://localhost:7474/db/data/node/370/relationships/out/-list|&|types","create_relationship":"http://localhost:7474/db/data/node/370/relationships","labels":"http://localhost:7474/db/data/node/370/labels","traverse":"http://localhost:747
4/db/data/node/370/traverse/returnType","all_relationships":"http://localhost:7474/db/data/node/370/relationships/all","all_typed_relationships":"http://localhost:7474/db/data/node/370/relationships/all/-list|&|types","property":"http://localhost:7474/db/data/node/370/propert
ies/key","self":"http://localhost:7474/db/data/node/370","incoming_relationships":"http://localhost:7474/db/data/node/370/relationships/in","properties":"http://localhost:7474/db/data/node/370/properties","incoming_typed_relationships":"http://localhost:7474/db/data/node/370/re
lationships/in/-list|&|types","data":"name":"empty","description":"An empty board.","id":"Mrw7M8myg",["boards":[],"group":null]]] (Parameter 'content')
---> System.ArgumentException: Accessed JArray values with invalid key value: "data". Int32 array index expected.
at Newtonsoft.Json.Linq.JArray.get_Item(Object key)
at Neo4jClient.Serialization.CommonDeserializerMethods.Map(DeserializationContext context, Object targetObject, JToken parentJsonToken, IEnumerable`1 typeMappings, Int32 nestingLevel)
at Neo4jClient.Serialization.CommonDeserializerMethods.CreateAndMap(DeserializationContext context, Type type, JToken element, IEnumerable`1 typeMappings, Int32 nestingLevel)
at Neo4jClient.Serialization.CommonDeserializerMethods.MutateObject(DeserializationContext context, JToken value, IEnumerable`1 typeMappings, Int32 nestingLevel, TypeMapping mapping, Type propertyType)
at Neo4jClient.Serialization.CommonDeserializerMethods.CoerceValue(DeserializationContext context, PropertyInfo propertyInfo, JToken value, IEnumerable`1 typeMappings, Int32 nestingLevel)
at Neo4jClient.Serialization.CypherJsonDeserializer`1.<>c__DisplayClass22_0.<ReadProjectionRowUsingCtor>b__0(JToken cell, Int32 cellIndex)
at System.Linq.Enumerable.SelectIterator[TSource,TResult](IEnumerable`1 source, Func`3 selector)+MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Neo4jClient.Serialization.CypherJsonDeserializer`1.ReadProjectionRowUsingCtor(DeserializationContext context, JToken row, IDictionary`2 propertiesDictionary, IList`1 columnNames, IEnumerable`1 jsonTypeMappings, ConstructorInfo ctor)
at Neo4jClient.Serialization.CypherJsonDeserializer`1.<>c__DisplayClass21_1.<ParseInProjectionMode>b__5(JToken token)
at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Neo4jClient.Serialization.CypherJsonDeserializer`1.Deserialize(String content)
--- End of inner exception stack trace ---
板级:
public class Board
[JsonProperty("id")]
public string Id get; set;
[JsonProperty("name")]
public string Name get; set;
[JsonProperty("description")]
public string Description get; set;
组类:
public class Groups
[JsonProperty("group")]
public Group Group get; set;
[JsonProperty("boards")]
public IEnumerable<Board> Boards get; set;
编辑:我也尝试过挤入三元条件:Groups = groups == null ? null : groups.CollectAs<Groups>()
,但这会引发 NotSupportedException,说“不支持 FullConditionalExpression”
【问题讨论】:
因为 collect() 是一个聚合,所以先尝试做 collect(),然后是列表中的 CASE。WITH collect(groups) as allGroups RETURN CASE WHEN allGroups = [] THEN NULL ELSE allGroups END as allGroups
【参考方案1】:
啊,我解决了。解决方案最终变得非常明显! Return.As<Groups>
必须是 Return.As<IEnumerable<Groups>>
【讨论】:
以上是关于Neo4jClient "CASE WHEN" 连同返回的主要内容,如果未能解决你的问题,请参考以下文章