c# - EF6如何自定义复数

标签 c# entity-framework-6

我正在尝试使用界面 IPluralizationService自定义我的实体的多元化没有成功!

必须使用 Inflector 对所有实体进行复数化图书馆。

尝试

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();
    }
}

在我的上下文中;

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

最佳答案

根据msdn的文章Code-Based Configuration (EF6 onwards) <强>节Using DbConfiguration ,只需将 DbConfiguration 类放在与 DbContext 类相同的程序集中即可。

不过您可以手动指定它,如explained in the article通过在 DbContext 中使用配置文件或注释。

配置文件:

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

注释:

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

或者

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

备注:

这些例子直接来 self 链接的文章

关于c# - EF6如何自定义复数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17471391/

相关文章:

c# - SaveFileDialog 上的 DialogResult.OK 不起作用

multithreading - 线程安全 Entity Framework 6

asp.net - 如何使用另一个表中的列来引用两个表 - Entity Framework

c# - 任务完成

c# - C# NUnit 的 BDD

javascript - JQuery 最接近的元素,来自 GridView 中的 TextBox

c# - WP8 LongListSelector 中的自动高度图像

c# - Entity Framework 审计一对多关系并捕获相关实体

c# - Entity Framework 6 - 仅将一个语句映射到存储过程

c# - 在 ViewModel 中具有静态 DbContext 的 WPF 应用程序