-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance scaffolding to prepend schema names to entity classes #488
Comments
I believe you may be able to solve this with the renaming feature - if you can share a simple repro (DDL scripts), I can have a look. |
`USE [master] CREATE DATABASE [TestDb] ALTER DATABASE [TestDb] SET COMPATIBILITY_LEVEL = 130 ALTER DATABASE [TestDb] SET MULTI_USER ALTER DATABASE [TestDb] SET QUERY_STORE = OFF USE [TestDb] ALTER DATABASE [TestDb] SET READ_WRITE CREATE SCHEMA [IR]; CREATE TABLE [IR].[Attribute]( CREATE SCHEMA [Com]; CREATE TABLE [Com].[Log]( CREATE SCHEMA [TV]; CREATE TABLE [TV].[Attribute]( |
OK, I get this without doing anything custom:
What is your desired outcome? |
Like this:
OR
i.e. prepend schema names to entity classes for the |
public partial class NorthwindContext : DbContext
{
public virtual DbSet<IrAttribute> IrAttributes { get; set; }
public virtual DbSet<Log> Logs { get; set; }
public virtual DbSet<TvAttribute> TvAttributes { get; set; } efpt.renaming.json: [
{
"UseSchemaName": false,
"SchemaName": "IR",
"Tables": [
{
"Name": "Attribute",
"NewName": "IrAttribute"
}
]
},
{
"UseSchemaName": false,
"SchemaName": "TV",
"Tables": [
{
"Name": "Attribute",
"NewName": "TvAttribute"
}
]
}
]
|
But can this be applied to all cases (tables)? And not specifically for two tables? That is, for all tables prepend schema name. |
Yes, if you add it to the file (you could create a small tool to build the json file, see the wiki for a sample tool) |
Thank you! |
@GeorgyRezchikov latest daily also allows you to use regular expression for name replacements |
This is an awesome tool thanks! I was wondering if it's possible to update the configuration file anyway to have multiple ModelNamespace and Output paths for a single dbcontext? What I'm trying to achieve is to save the entities (i.e. db tables) into an 'Entities' folder and the models (i.e. db views) into a 'Models' folder. Currently I'm doing the updates manually each time I refresh the dbcontext and associated objects. |
@rasaconsulting-sandy why are you posting this on a closed issue? What are "db views" - there is no distinction between views and tables with EF Core, so if that is what you mean, the answer is probably no. |
Hi Erik, |
In the EF repository(https://github.com/dotnet/efcore), the question was raised about the presence in the database of two tables with the same names but in different schemas.
dotnet/efcore#3988
dotnet/efcore#12432
Is it possible to solve this problem with your tool?
EF Core Power Tools version: 2.4.157
Database engine: SQL Server
Visual Studio version: Visual Studio 2019 15.7
The text was updated successfully, but these errors were encountered: