EntityFramework Core 数据库首先采用复数表名的方法 [英] EntityFramework Core database first approach pluralizing table names

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

问题描述

我们现有的数据库带有复数表名.例如Documents.我正在尝试使用新的 EF CoreAsp.Net Core 和基于本文的数据库优先方法 这里

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

脚手架-DbContext"Server=(local);Database=MyDatabase;Trusted_Connection=True;"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天全站免登陆