ridermansb
ridermansb

Reputation: 11069

How to customize the pluralization EF6

I'm trying to use the interface IPluralizationService to customize the pluralization of my entities without success!

Necessary that all entities are pluralized using the Inflector library.

Attempts

class Config : DbConfiguration
{
    public Config()
    {
        SetPluralizationService(new CustomPluralization());
    }
}

class CustomPluralization : IPluralizationService
{
    public string Pluralize(string word)
    {
        return word.Pluralize();
    }

    public string Singularize(string word)
    {
        return word.Singularize();
    }
}

In my context;

modelBuilder.Configurations.Add<Config>(.. ?? ..)

Upvotes: 3

Views: 1149

Answers (1)

7hi4g0
7hi4g0

Reputation: 3809

According to msdn's article Code-Based Configuration (EF6 onwards) section Using DbConfiguration, it is sufficient to simply place your DbConfiguration class in the same assembly as your DbContext class.

Nevertheless you can specify it manually, as explained in the article by using either the config file or an annotation in your DbContext.

Config file:

<entityFramework codeConfigurationType="MyNamespace.MyDbConfiguration, MyAssembly">
    <!-- Your EF config -->
</entityFramework>

Annotation:

[DbConfigurationType("MyNamespace.MyDbConfiguration, MyAssembly")] 
public class MyContextContext : DbContext 
{ 
}

Or

[DbConfigurationType(typeof(MyDbConfiguration))] 
public class MyContextContext : DbContext 
{ 
}

Note:

These examples are directly from the article I linked

Upvotes: 1

Related Questions