EntityFramework Core数据库第一种方法是使表名复数 [英] EntityFramework Core database first approach pluralizing table names

查看:618
本文介绍了EntityFramework Core数据库第一种方法是使表名复数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们现有的数据库具有多个表名.例如Documents.我正在根据本文EF Core和Asp.Net Core与数据库优先方法一起使用rel ="noreferrer">此处

We have existing database with pluralized table names. For Example Documents. I am trying to use new EF Core and Asp.Net Core with database first approach based on this article here

我运行以下命令从现有数据库创建模型

I run the following command to create models from the existing database

Scaffold-DbContext 服务器=(本地);数据库= MyDatabase;受信任的连接=真实;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir模型

Scaffold-DbContext "Server=(local);Database=MyDatabase;Trusted_Connection=True;"Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

但是,当我运行脚手架命令时,它将创建具有复数名称的模型.例如,将Documents表转换为型号名称Documents.

However when I run scaffolding command it creates models with plural names. For example Documents table converted to model name Documents.

如何更改此设置,以便可以对模型使用单数命名约定? (我无法更改数据库中的表名)

How do I change this so it can use singular naming convention for model? (I cannot alter table names in database)

请注意,关于相同问题,我很少读过SO文章,但他们大多关注代码优先方法.我正在使用数据库优先方法.

Note that I have read few post on SO related to same issue but they mostly concerned with code first approach. I am using database first approach.

推荐答案

EF Core工具当前不包含用于以您描述的方式自定义对现有数据库进行反向工程的输出的选项.当前,您唯一可行的选择是修改生成的代码.

The EF Core tools do not currently include options to customise the output of reverse engineering an existing database in the way that you describe. Currently, your only realistic option is to modify the generated code.

这篇关于EntityFramework Core数据库第一种方法是使表名复数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆