Suppose I have the following class to be serialized and stored as a RavenDB's document:
public class Block
{
public string Id { get; set; }
public List<List<dynamic>> data { get; set; }
}
After storing, a document like this can be seen in the database:
{
"Id": "f539770a",
"columns": [
[ 90, 91, 92, 93, 94 ],
[ "C", "D", "A", "B", "C" ]
] }
I want to execute a query to retrieve the Nth list of values inside the "Columns" field:
session.Query<Block>().Where(b => b.Id == "f539770a").Select(b =>b.columns[i]);
And I get the following Error:
{"Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[System.Object]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath '__document_id'."}
It seems like the query is working (the server returns http 200), but there is a client-side deserialization problem.
Am I missing something?
Thanks!!
UPDATE:
I changed the data structure as the error seems to suggest:
public class Column
{
public List<dynamic> data { get; set; }
}
public class Block
{
public string Id { get; set; }
public List<Column> columns { get; set; }
}
The stored document is like:
{
"Id": "f539770a",
"columns": [
{ "data": [ 95, 96, 97, 98, 99 ] },
{ "data": [ "D", "A", "B", "C", "D" ] }
]}
After executing this query:
session.Query<Block>().Include<Block>(b => b.columns).Where(b => b.parentFileId == dbFileDescriptor.Id).Select(b => b.columns[i])
I get no exception, but the nested array is not loaded: