Closed stevestokes closed 3 years ago
It is actually the EF Core design library that suggests this.
If you use "Use database names" and EF Core 5, it should work as expected.
It is actually the EF Core design library that suggests this.
If you use "Use database names" and EF Core 5, it should work as expected.
So, it sort of does. If I use "Use database names" the ID fields are preserved. However, a table name like Users is preserved as Users. In previous versions, this was singularized to "User".
So with "Use database names" ID columns = ID Users = Users db.Users.Add(...) new Users() { ... }
Without "Use database names" ID columns = Id Users = User db.User.Add(...) new User() { ... }
As you can see it flips between resulting in massive code changes either way (assuming an existing large codebase).
Have you enabled Pluralization? That should fix the Users <> User issue, I think
As you can see it flips between resulting in massive code changes either way (assuming an existing large codebase).
What generated that codebase?? You can opt-in to use the EF6 pluralizer...
If I uncheck "Use table and column names directly from the database" it results in
User { UserId }
If that is checked it results in Users { UserID }
DB:
Option 1:
results in:
Option 2:
results in:
Yes, those are the current options.
What is the actual issue?
In previous versions of this software I was able to pluralize and preserve tables names/id columns:
public partial class User
{
public int UserID { get; set;}
}
Notice User is singular on the class and ID is not Id
Which EF Core version did you pick??
Please provide a sample CREATE Table script, and I will have a look.
Thanks!
EF Core 3.1.10
CREATE TABLE [dbo].[Users](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[Username] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[UserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
I wonder what "previous version of the tool" you are referring to - this has never worked until EF Core 5.
I recently updated it but it was about a year old, still on vs2019
Ah, I used to have an quirky option to fix Id => ID. I removed that.
Please try EF Core 5 scaffolding.
Any update with trying EF Core 5?
As expected, this works with EF Core 5 scaffolding:
public partial class User
{
public int UserID { get; set; }
public string Username { get; set; }
}
I'm running into this as well on EF Core 6. I don't want to use EF Core 5 as I'm migrating from EDMX and don't want to lose the many-to-many features. I'll probably just rename the references by hand.
@MisinformedDNA are you not able to use on of the many renaming options?
Sorry, I honestly didn't think this would work.
"ColumnPatternReplaceWith": "ID",
"ColumnRegexPattern": "ID$",
@MisinformedDNA so that worked for you?
Yep. Thanks for your hard work on this awesome project.
@MisinformedDNA really appreciate your feedback and help.
Describe what is not working as expected. Power tools is forcing the column casing in the models. In the database an identity column is set as EntityID casing and when the model renders it changes it to EntityId
Steps to reproduce
Include a complete description that I can redo to reproduce the issue. Build a model from a table with capital casing on ID
Further technical details
EF Core Power Tools version: 2.5.277.0
Database engine: SQL Server
Visual Studio version: 2019