在RavenDB中指定集合名称 [英] Specifying Collection Name in RavenDB

查看:79
本文介绍了在RavenDB中指定集合名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以可以说我有3个对象:水果,苹果和橘子.水果是苹果和橘子的抽象基类.当我使用session.Store(myApple)时,它将其放入Apples集合中. myOrange存储在Oranges集合中.说得通.

So lets say I have 3 objects Fruit, Apple and Orange. Fruit is the abstract base class for Apple and Orange. When I use session.Store(myApple), it puts it into the Apples collection. myOrange stores in the Oranges collection. Makes sense.

我可以告诉Raven我想要一个可以装苹果或橙子的水果系列吗? Mongodb允许这样做,因为它使我可以明确指定集合名称. RavenDB集合文档说:

Can I tell Raven that I want a Fruits collection that could hold Apples or Oranges? Mongodb allows this since it lets me explicitly specify the collection name. The RavenDB collections documentation says:

预期的使用模式是将集合用于分组 具有类似结构的文档,尽管不是必需的.从 从数据库的角度来看,一个集合只是一组文档 拥有相同的实体名称.

The expected usage pattern is that collections are used to group documents with similar structure, although that is not required. From the database standpoint, a collection is just a group of documents that share the same entity name.

我希望它类似于:session.Store< Fruit>(myApple)或session.Store("Fruits",myApple)

I'd expect it to be something like: session.Store<Fruit>(myApple), or session.Store("Fruits", myApple)

有什么想法吗?谢谢.

推荐答案

锥子, 您可以使用:

session.Store(apple);
session.Advanced.GetMetadataFor(apple)[Constants.RavenEntityName] = "Fruits";

那是很长的路要走. 更好的方法是在全局添加此逻辑,看起来像这样:

That is the long way to do so. A much better way would be to add this logic globally, it looks something like this:

store.Conventions.FindTypeTagName = 
   type => type.IsSubclassOf(typeof(Fruit)) ? 
       DocumentConvention.DefaultTypeTagName(typeof(Fruit)) : 
       DocumentConvention.DefaultTypeTagName(type);

这将处理所有问题.

这篇关于在RavenDB中指定集合名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆