本文介绍了如何用Entity Framework Core中的DbSet属性名称复制DbContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Package Manager Console 中使用 Scaffold-DbContext 命令来创建和重新创建上下文和实体存在的SQL Server数据库:

I use Scaffold-DbContext command in Package Manager Console to create and re-create context and entities for an existed SQL Server database:

Scaffold-DbContext -provider EntityFramework.MicrosoftSqlServer -connection "my connection string"

它完美地工作,除了一件事: DbSet 单数形式:

It works perfectly except one thing: DbSet's have property names in singular form:

public partial class MyDbContext : DbContext
{
    public virtual DbSet<Request> Request { get; set; }
    public virtual DbSet<RequestHeader> RequestHeader { get; set; }
}

我喜欢这些名字复数形式(请求等)。除了web搜索,我检查了命令语法:

I prefer these names to be in plural form (Requests etc.). In addition to web search I checked command syntax:

get-Help Scaffold-DbContext -detailed

没有发现任何更改此行为。这是我的 packages.config

And found nothing to change this behaviour. Here is my packages.config:

<packages>
  <package id="EntityFramework.Commands" version="7.0.0-rc1-final" targetFramework="net46" />
  <package id="EntityFramework.Core" version="7.0.0-rc1-final" targetFramework="net46" />
  ...
</packages>

如何在脚手架时多元化 DbSet 名称?

How to pluralize DbSet names when scaffolding?

更新2017-04: DB实体框架Core 1.1中现在可以进行首个脚手架复合化。有关详细信息,请阅读我的。

UPDATE 2017-04: DB First scaffolding pluralization is now possible in Entity Framework Core 1.1. Read my answer below for details.

推荐答案

在RC1的EF7中不支持多项化。在这里跟踪EF7脚手架的这个和其他限制:

Pluralization is not supported in EF7 as of RC1. This and other limitations of EF7 scaffolding are being tracked here: https://github.com/aspnet/EntityFramework/issues/4038

这篇关于如何用Entity Framework Core中的DbSet属性名称复制DbContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 03:00