在RavenDB中查询动态属性(Querying dynamic properties in RavenDB)

编程入门 行业动态 更新时间:2024-10-23 01:56:24
在RavenDB中查询动态属性(Querying dynamic properties in RavenDB)

我在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

更多推荐

本文发布于:2023-07-28 19:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308145.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   动态   RavenDB   properties   dynamic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!