Skip to content

Enhance scaffolding to prepend schema names to entity classes #12432

Closed as not planned

Description

The "all knowing" dba powers that be on my project have decided that schemas are the best thing since sliced bread. Which might be okay if they didn't also have identically named tables (with different columns) in multiple schemas. For instance [Schema1].[TableA] and [Schema2.TableA] and [Schema3.TableA]. When EF scaffolds that database you will get entity classes for TableA, TableA1, and TableA2. The only way to tell them apart is to look at the generated context file, wherein the schema is incluided in the fluent definition.

Further problems ensue if another schema with the same table name is added and its schema name is alphabetically before the existing ones. At that point re-scaffolding will generate TableA, TableA1, TableA2, TableA3, and TableA4, BUT TableA (against which you probably wrote code) will now point to the newly added schema instead of the one to which it pointed initially, and your code will likely break.

Adding, (at least optionally), the schema name to the entity class name would avoid all those issues and simplify updates when the database changes.

Steps to reproduce

  1. Create a database with at least 2 schemas having identically named tables (but with different column definitions).
  2. Execute the scaffold command.
  3. Look at the generated entity classes and db context.

Further technical details

EF Core version: 2.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win 10
IDE: Visual Studio 2017 15.7.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions