RavenDB changes metadata "Raven-Entity-Name"
Asked Answered
S

1

5

I noticed that when I add a document to RavenDB and see the "Raven-Entity-Name" metadata it makes it plural. E.g. if my model name was Product it changes it to Products. Why such kind for behavior?

If I have create an index I am forced to use docs.Products

Statist answered 3/9, 2010 at 12:59 Comment(0)
G
12

It's part of the philosophy of RavenDB to do convention over configuration, so it does this by default.

But you can override it if you want to, you can do something like this:

_documentStore = new DocumentStore { Url = "http://localhost:8080/" };
_documentStore.Conventions.FindTypeTagName = t =>
{
    if (t.Name == "MyClass")
        return "MyClassBlahBlah";
    else
        return Raven.Client.Util.Inflector.Pluralize(t.Name); 
};

_documentStore.Initialize(); 

See this thread on the RavenDB discussion group for more info

Gentoo answered 3/9, 2010 at 16:29 Comment(3)
so this means for every model i will have to write code. Is there any single point configuration whereby it stops pluralizing for the application or ravendb itself?Statist
@ajay_whiz, Matt says everything you need to stop pluralizing. Try: _documentStore.Conventions.FindTypeTagName = t => t.Name;Dermott
Thanks for this! Solution also helps when you're trying to save a doc with a non-standard Id after loading and changing it.Calder

© 2022 - 2024 — McMap. All rights reserved.