[英]How to disable conventions in Microsoft.EntityFrameworkCore?
I'm using SQLite with EFCore, but I got a problem... how can I disable Conventions like Pluralize?我正在将 SQLite 与 EFCore 一起使用,但是我遇到了一个问题……我如何禁用像 Pluralize 这样的约定? Is it possible?是否可以?
My ModelBuilder has not a property Conventions...我的 ModelBuilder 没有属性约定...
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder. [NOT HAS PROPERTY CONVENTION]
}
You can disable pluralizing naming convention as shown below.您可以禁用复数命名约定,如下所示。
public static class ModelBuilderExtensions
{
public static ModelBuilder RemovePluralizingTableNameConvention(this ModelBuilder modelBuilder)
{
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
{
if (entityType.ClrType == null)
continue;
entityType.Relational().TableName = entityType.ClrType.Name;
}
return modelBuilder;
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.RemovePluralizingTableNameConvention();
}
No!不! It's not possible in ef core.这在 ef 核心中是不可能的。 as @Mustafa told, you can override convention by fluent API configuration.正如@Mustafa 所说,您可以通过流畅的 API 配置覆盖约定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.