简体   繁体   English

索引基类ravendb的所有派生类

[英]Index all derived classes of base class ravendb

Our project has a framework and an own code base, which implements entities of the framework. 我们的项目有一个框架和一个自己的代码库,它实现了框架的实体。

The idea is also to have several indexes in the framework that will return the results of all inheritances of certain framework types like user. 这个想法也是在框架中有几个索引,它们将返回某些框架类型(如user)的所有继承的结果。

Apparantly, the only way Raven supports this (without creating the index on the highest level and manually adding maps) is to store all objects in the same collection by overwriting the Clr-type. 显然,Raven支持此功能的唯一方法(不在最高级别创建索引并手动添加地图)是通过覆盖Clr类型将所有对象存储在同一集合中。 However, this means we lose the derived information and cannot query on it. 但是,这意味着我们丢失了派生信息,无法对其进行查询。

Some samples: 一些样品:

class A { 
    public string Id {get; set; }, 
    public string Name {get; set; } 
}
class B : A { }
class C : A { }
class D : C { } 

Then I want to query something along the lines of: 然后我想查询以下内容:

store.Query<IndexOfA>().Where(a => a.Name == "foo").As<A>().ToList();

AND be able to still do this; 并且能够仍然这样做;

store.Query<IndexOfC>().As<C>().ToList()

My idea was to add a convention that saves both the derived and the base class to the metadata when storing documents in RavenDB, but I have no idea how to go about this and cannot find any documentation on the subject. 我的想法是在RavenDB中存储文档时添加一个将派生类和基类保存到元数据的约定,但我不知道如何解决这个问题,并且无法找到有关该主题的任何文档。

Any ideas? 有任何想法吗?

You can create an index that used a multi map index with AddMapForAll<Base> , which will generate a separate entry for each derived class. 您可以使用AddMapForAll<Base>创建一个使用多映射索引的索引, AddMapForAll<Base>为每个派生类生成一个单独的条目。 You could then use that index to do polymorphic queries. 然后,您可以使用该索引进行多态查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM