我在Raven中查询动态属性时遇到了一些麻烦。
这是我的课程:
public class Parent { public string ID { get; set; } public dynamic Child { get; set; } } public class Son { public int A { get; set; } public Guid Key { get; set; } } public class Daughter { public int A { get; set; } public Guid Key { get; set; } }我想要做的是索引父母,他们的孩子是儿子,而不是女儿,并通过子属性'A'或'Key'索引。 在我的例子中,子节点不能从接口继承,因为真正的子类看起来完全不同。 这些类是为与场景匹配的测试而构建的。
我到目前为止构建的索引如下所示:
public class DynamicIndex : AbstractIndexCreationTask { public override Raven.Abstractions.Indexing.IndexDefinition CreateIndexDefinition() { return new IndexDefinition() { Map = @"from doc in docs.Parent select new { A = doc.Dynamic.A, B = doc.Dynamic.B }" }; } }这个索引有效,除了我似乎无法过滤掉匹配一种类型而不是另一种类型的儿童。 序列化的JSON for Child包含一个名为'$ type'的属性,它是Type的全名。 我的直觉告诉我用它来区分子类型,但我不知道如何访问它。
如何扩展索引的地图以包含'$ test'属性,还是有另一种方法来过滤匹配特定类型的子项?
I'm having some trouble querying dynamic properties in Raven.
Here are my classes:
public class Parent { public string ID { get; set; } public dynamic Child { get; set; } } public class Son { public int A { get; set; } public Guid Key { get; set; } } public class Daughter { public int A { get; set; } public Guid Key { get; set; } }What I'm trying to do is index parents whose child is a son, but not a daughter, and index by the child properties 'A' or 'Key'. In my case, the children can't inherit from an interface because the real child classes will look entirely different from each other. These classes are built for a test that matches the scenario.
The index I've built so far looks like this:
public class DynamicIndex : AbstractIndexCreationTask { public override Raven.Abstractions.Indexing.IndexDefinition CreateIndexDefinition() { return new IndexDefinition() { Map = @"from doc in docs.Parent select new { A = doc.Dynamic.A, B = doc.Dynamic.B }" }; } }This index works except I cannot seem to filter out children who match one type and not the other. The serialized JSON for Child contains a property called '$type' which is the full name of the Type. My instinct tells me to use this to differentiate between child types but I don't know how to access it.
How can I expand my index's map to include the '$test' property or is there another way to filter for children matching a particular type?
最满意答案
Map = @"from doc in docs.Parent select new { A = doc.Dynamic.A, B = doc.Dynamic.B, Type = doc.Dynamic[""$type""] }"应该管用
Map = @"from doc in docs.Parent select new { A = doc.Dynamic.A, B = doc.Dynamic.B, Type = doc.Dynamic[""$type""] }"Should work
更多推荐
发布评论