I'm dynamically creating some collections in my database. I instantiate ExpandoObjects
and manually set the entity name. This works fine.
Now I need to get a list of entities, with the associated properties (which should be the same for all the documents in the collection, but not necessarily)
The result should be a list of:
class Collection
{
string Name;
string[] Properties;
}
Now, I know I can create an index that references ["@metadata"]["Raven-Entity-Name"]
, and since JSON objects (or RavenJObjects
, or ExpandoObjects
) are dictionaries, I thought I would be able to retrieve doc.Keys
(I think this is what doesn't work)
This is my work in progress, which does not work (the Properties
array contains one null
per document in the collection)
Map:
from doc in docs
let Name = doc["@metadata"]["Raven-Entity-Name"]
where Name.StartsWith("External_")
select new { Name, Properties = doc.Keys }
Reduce:
from result in results
group result by result.Name into r
select new { Name = r.Key, Properties = r.Select(x => x.Properties).Distinct() }