Search code examples
c#linqpluralize

Can I use linq's method of pluralizing a term?


In .net 3.5 if I generate a linq to sql data context, it does some wonderful magic to pluralize names. In my code I need to pluralize some terms. Can I use whatever method Linq is using to generate my plurals?


Solution

  • LINQ to SQL doesn't expose its pluralization logic. A quick check with Reflector reveals that it's not using a terribly complex algorithm though:

    If it ends with 'x', 'ch', 'sh' or 'ss', then add 'es'.
    If it ends with 'y' preceded by a consonant, remove the y and add 'ies'.
    Otherwise, add 's'.

    If .NET 4 is an option, then EF's PluralizationService is much more thorough. Just in case you ever need to pluralize 'pneumonoultramicroscopicsilicovolcanoconiosis'.