Example needed for controlling the automatic pluralisation of raven entity name

609 views
Skip to first unread message

Bevermans

unread,
Jul 16, 2010, 7:00:51 AM7/16/10
to ravendb
I have some entities for which the plural form of a raven collection
is not correct (for example Company versus Companies).

Now I found a hint that I have to do something with the
Conventions.FindTypeTagName but I do not know how to do this.

Thanks for any help!

Chris

unread,
Jul 16, 2010, 11:19:14 AM7/16/10
to rav...@googlegroups.com
The default FindTypeTagName convention uses the Raven.Util.Inflector class to pluralize type names. To alter this behavior, try something like this:

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

_documentStore.Initialize();

Chris

unread,
Jul 16, 2010, 11:20:01 AM7/16/10
to rav...@googlegroups.com
Er... change typeof(string) to typeof(MyClass) where MyClass is the type for which you want to alter the collection name.

Daniel Cazzulino

unread,
Jul 16, 2010, 12:08:11 PM7/16/10
to rav...@googlegroups.com
or you can directly use the System.Data.Entity.Design.PluralizationServices.PluralizationService :)
(from EF, System.Data.Entity.Design)

/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471

Ayende Rahien

unread,
Jul 18, 2010, 4:13:02 AM7/18/10
to rav...@googlegroups.com
Hm,
Does that support i18n?

Daniel Cazzulino

unread,
Jul 18, 2010, 2:36:48 PM7/18/10
to rav...@googlegroups.com

yup, you create the service for a given culture. 

in .NET 4.0, however (my en-US install, anyway), it throws for anything but "en"

public static PluralizationService CreateService(CultureInfo culture)
{
    EDesignUtil.CheckArgumentNull<CultureInfo>(culture, "culture");
    if (culture.TwoLetterISOLanguageName != "en")
    {
        throw new NotImplementedException("We don't support locales other than english yet");
    }
    return new EnglishPluralizationService();
}

from android nexus1

Bevermans

unread,
Jul 19, 2010, 5:33:58 AM7/19/10
to ravendb
Thank you all for the suggestions! I now use Chris suggestion and it
works perfect!

Yours sincerely,

Evert Wiesenekker

ajay_whiz

unread,
Sep 6, 2010, 7:32:21 AM9/6/10
to ravendb
so this means for every model i will have to write code. Is there any
single point configuration whereby it stops pluralizing for whole
application or ravendb itself?

Ayende Rahien

unread,
Sep 6, 2010, 8:39:51 AM9/6/10
to rav...@googlegroups.com
I am sorry, what exactly do you want? 
If you want to stop pluralization globably, just use:

conventions.FindTypeTagName = t=>t.Name;

ajay_whiz

unread,
Sep 6, 2010, 11:24:21 AM9/6/10
to ravendb
Thanks, I was looking for such setting in the RavenDB itself. So that
I won't have to write that code.

Ayende Rahien

unread,
Sep 8, 2010, 4:09:31 AM9/8/10
to rav...@googlegroups.com
That is in the client API, and that is a single line of code that you can provide when configuring the DocumentStore
Reply all
Reply to author
Forward
0 new messages