Specifying Collection Name in RavenDB

后端 未结 1 1785
一个人的身影
一个人的身影 2020-12-24 11:55

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 co

相关标签:
1条回答
  • 2020-12-24 12:42

    Awl, You can do it using:

    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);
    

    That will handle this for everything.

    0 讨论(0)
提交回复
热议问题