1

I would like to take advantage of the new ability to customize pluralization with EF6. I've searched the entire intertwangles but can't find a decent example.

I generate my model from the database (SQL Server) and I use custom T4 templates to generate the context and model classes.

From what I can tell, I should be able to create a class which inherits from DbConfiguration and simply place it in the model project. I have done this.

Public Class CustomConfiguration
    Inherits DbConfiguration

    Public Sub New()
        MyBase.New()
        SetPluralizationService(New CustomPluralizationService)
    End Sub
End Class

This class references CustomPluralizationService which I understand must implement IPluralizationService. Fine and dandy:

Imports System.Data.Entity.Infrastructure.Pluralization

Public Class CustomPluralizationService
    Implements IPluralizationService

    Public Function Pluralize(word As String) As String Implements System.Data.Entity.Infrastructure.Pluralization.IPluralizationService.Pluralize

    End Function

    Public Function Singularize(word As String) As String Implements System.Data.Entity.Infrastructure.Pluralization.IPluralizationService.Singularize

    End Function
End Class

Of course I should complete the implementation of the Pluralize and Singularize functions, but am at a loss how exactly to do it, as I cannot find a completed example anywhere, in any language. Can someone help, please?

The documentation on MSDN has cryptic garbage like this:

Function Pluralize ( _
    word As [%$TOPIC/dn176961_en-us_VS_113_3_0_0_0_0%] _
) As [%$TOPIC/dn176961_en-us_VS_113_3_0_0_0_1%]

Dim instance As [%$TOPIC/dn176961_en-us_VS_113_3_0_1_0_0%] 
Dim word As [%$TOPIC/dn176961_en-us_VS_113_3_0_1_0_1%] 
Dim returnValue As [%$TOPIC/dn176961_en-us_VS_113_3_0_1_0_2%] 

returnValue = instance.Pluralize(word)

[%$TOPIC/dn176961_en-us_VS_113_3_0_2_0_0%] Pluralize( 
    [%$TOPIC/dn176961_en-us_VS_113_3_0_2_0_1%] word 
)

[%$TOPIC/dn176961_en-us_VS_113_3_0_3_0_0%]^ Pluralize(
    [%$TOPIC/dn176961_en-us_VS_113_3_0_3_0_1%]^ word
)
whistle britches
  • 137
  • 2
  • 10
  • Perhaps after you pass the second grade (doubtful), they'll teach you to spell. – whistle britches Feb 23 '15 at 21:48
  • Wow, an age cutdown (ironic, considering that's the forte of 13 YO girls) combined with an unsupported claim of misspellings. No wonder you use vb.net. –  Feb 24 '15 at 15:02

0 Answers0