I am creating an application with several interconnected items. One of the things I would like to do, is easily fetch nested objects based on relationships. Say I have the json structure displayed below:
Categories = [
{
name: "projectors",
productTypes: [
{
name: "panasonic",
products: [
{
id: "d.1.1",
model: "PT-DZ680"
},
{
id: "d.1.2",
model: "PT-DZ680"
}]
}]
}]
I have so far created nodes for both categories, productTypes and products. And i've created a relationship between categories->productTypes and productTypes->products.
Based on the example given in Nested has_many relationships in cypher , i've formulated the following code.
var categoriesWithProducts = Client.Cypher
.Match(
"(category:Category) -[:ISUNDERCATEGORY]->(productType:ProductType)-[:ISTYPEOF]->(product:Product)")
.With((category, productType, product) => new
{
category,
productType,
products = product.CollectAs<Product>()
})
.With((category, productType, products) => new
{
category,
productTypes = "collect({Name: productType.Name, Products:products})"
})
.Return((category, productTypes) => new
{
Name = category.As<Category>().Name,
ProductTypes = productTypes.As<ProductType>()
})
.Results;
This is the closest I've come to returning the structure above. And it currently results in the following error:
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
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__AnonymousType3`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Proddler.Frontend.Models.ProductType, Proddler.Frontend, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
Include this raw JSON, with any sensitive values replaced with non-sensitive equivalents:
{ "columns" : [ "Name", "ProductTypes" ], "data" : [ [ "Skærme", [ { "Name" : "Panasonic", "Products" : [ { "labels" : "....net:7474/db/data/node/15/labels", "outgoing_relationships" : "....net:7474/db/data/node/15/relationships/out", "data" : { "Name" : "super awesomeSkærm", "Guid" : "28a16c87-135a-4afe-9bef-8470e1ece860", "Id" : "d.1.7" }, "traverse" : "....net:7474/db/data/node/15/traverse/{returnType}", "all_typed_relationships" : "....net:7474/db/data/node/15/relationships/all/{-list|&|types}", "self" : "....net:7474/db/data/node/15", "property" : "....net:7474/db/data/node/15/properties/{key}", "properties" : "....net:7474/db/data/node/15/properties", "outgoing_typed_relationships" : "....net:7474/db/data/node/15/relationships/out/{-list|&|types}", "incoming_relationships" : "....net:7474/db/data/node/15/relationships/in", "extensions" : { }, "create_relationship" : "....net:7474/db/data/node/15/relationships", "paged_traverse" : "....net:7474/db/data/node/15/paged/traverse/{returnType}{?pageSize,leaseTime}", "all_relationships" : "....net:7474/db/data/node/15/relationships/all", "incoming_typed_relationships" : "....net:7474/db/data/node/15/relationships/in/{-list|&|types}" }, { "labels" : "....net:7474/db/data/node/16/labels", "outgoing_relationships" : "....net:7474/db/data/node/16/relationships/out", "data" : { "Name" : "super awesomeSkærm2", "Guid" : "a3191f2e-2974-4d1b-a7cf-65200677e36c", "Id" : "d.1.7" }, "traverse" : "....net:7474/db/data/node/16/traverse/{returnType}", "all_typed_relationships" : "....net:7474/db/data/node/16/relationships/all/{-list|&|types}", "self" : "....net:7474/db/data/node/16", "property" : "....net:7474/db/data/node/16/properties/{key}", "properties" : "....net:7474/db/data/node/16/properties", "outgoing_typed_relationships" : "....net:7474/db/data/node/16/relationships/out/{-list|&|types}", "incoming_relationships" : "....net:7474/db/data/node/16/relationships/in", "extensions" : { }, "create_relationship" : "....net:7474/db/data/node/16/relationships", "paged_traverse" : "....net:7474/db/data/node/16/paged/traverse/{returnType}{?pageSize,leaseTime}", "all_relationships" : "....net:7474/db/data/node/16/relationships/all", "incoming_typed_relationships" : "....net:7474/db/data/node/16/relationships/in/{-list|&|types}" }, { "labels" : "....net:7474/db/data/node/17/labels", "outgoing_relationships" : "....net:7474/db/data/node/17/relationships/out", "data" : { "Name" : "super awesomeSkærm2", "Guid" : "a3191f2e-2974-4d1b-a7cf-65200677e36c", "Id" : "d.1.7" }, "traverse" : "....net:7474/db/data/node/17/traverse/{returnType}", "all_typed_relationships" : "....net:7474/db/data/node/17/relationships/all/{-list|&|types}", "self" : "....net:7474/db/data/node/17", "property" : "....net:7474/db/data/node/17/properties/{key}", "properties" : "....net:7474/db/data/node/17/properties", "outgoing_typed_relationships" : "....net:7474/db/data/node/17/relationships/out/{-list|&|types}", "incoming_relationships" : "....net:7474/db/data/node/17/relationships/in", "extensions" : { }, "create_relationship" : "....net:7474/db/data/node/17/relationships", "paged_traverse" : "....net:7474/db/data/node/17/paged/traverse/{returnType}{?pageSize,leaseTime}", "all_relationships" : "....net:7474/db/data/node/17/relationships/all", "incoming_typed_relationships" : "....net:7474/db/data/node/17/relationships/in/{-list|&|types}" } ] }, { "labels" : "....net:7474/db/data/node/22/labels", "outgoing_relationships" : "....net:7474/db/data/node/22/relationships/out", "data" : { "Name" : "Sony Bravia 2", "Guid" : "ad4263d4-7647-46e0-a53c-a6b232c47457", "Id" : "d.1.8" }, "traverse" : "....net:7474/db/data/node/22/traverse/{returnType}", "all_typed_relationships" : "....net:7474/db/data/node/22/relationships/all/{-list|&|types}", "self" : "....net:7474/db/data/node/22", "property" : "....net:7474/db/data/node/22/properties/{key}", "properties" : "....net:7474/db/data/node/22/properties", "outgoing_typed_relationships" : "....net:7474/db/data/node/22/relationships/out/{-list|&|types}", "incoming_relationships" : "....net:7474/db/data/node/22/relationships/in", "extensions" : { }, "create_relationship" : "....net:7474/db/data/node/22/relationships", "paged_traverse" : "....net:7474/db/data/node/22/paged/traverse/{returnType}{?pageSize,leaseTime}", "all_relationships" : "....net:7474/db/data/node/22/relationships/all", "incoming_typed_relationships" : "....net:7474/db/data/node/22/relationships/in/{-list|&|types}" } ] } ] ] ] } Parameter name: content
First of all, I have now idea whether my approach is correct. Secondly, I have no clue how to resolve the error I am now facing.
I apologize if my question is trivial!
Thank you in advance!