efcore icon indicating copy to clipboard operation
efcore copied to clipboard

UseDatabaseNames not working in columns names

Open piyey opened this issue 9 years ago • 18 comments

I use the flag --use-database-names when generating my classes, table names are done fine, but field names are still PascalCaseify.

Regards!

piyey avatar Sep 14 '17 19:09 piyey

@piyey - EF Core does not generate fields. Are you referring to Properties generated inside Entitytypes?

smitpatel avatar Sep 14 '17 19:09 smitpatel

I mean field names of my tables are PascalCaseify when generating POCO classes.

piyey avatar Sep 14 '17 19:09 piyey

Can you post example of one of incorrectly generated POCO classes?

smitpatel avatar Sep 14 '17 19:09 smitpatel

I'm not on my dev machine, so I will try to explain it on the fly (sorry).

My table:

this_is_my_table -field_one INT -field_two INT -field_three INT

Generated POCO classes:

public class this_is_my_table { public int FieldOne {get;set;} public int FieldTwo {get;set;} public int FieldThree {get;set;} }

piyey avatar Sep 14 '17 19:09 piyey

If you see, table name is not PascalCaseify in the class name, but field names do in properties.

piyey avatar Sep 14 '17 19:09 piyey

Presently Column Naming does not switch based on UseDatabaseNames (like DbSet & EntityType naming does).

@piyey in C# public int Property {get; set;} is auto-property whereas public int Field; is field (no getter/setter for a field). Therefore it was bit confusing.

Another interesting observation. We have convention to use DbSet name as table name. Shouldn't reveng scaffold dbset name same as table name regardless of naming strategy.

smitpatel avatar Sep 14 '17 19:09 smitpatel

Do you mean UseDatabaseNames apply only to table name but not to columns names?

piyey avatar Sep 14 '17 19:09 piyey

@smitpatel sorry for Field word, I meant column (in spanish we call fields to the columns of a table)

piyey avatar Sep 14 '17 19:09 piyey

Do you mean UseDatabaseNames apply only to table name but not to columns names?

Yes. At least in current code base. We will discuss in team meeting if that is expected behavior or column naming was left out in hindsight.

smitpatel avatar Sep 14 '17 19:09 smitpatel

Same issues, additional details:

Column Names are still changed, see EQID below:

modelBuilder.Entity<DCUTRANSLATIONS>(entity =>
            {
                entity.HasKey(e => new { e.Eqid, e.Analyte });

                entity.Property(e => e.Eqid)
                    .HasColumnName("EQID")
                    .HasMaxLength(20);

...

Command used: dotnet ef dbcontext scaffold "Server=SLCOHW3DSILIO1;Database=sunrise_demo_data;Trusted_Connection=True;" "Microsoft.EntityFrameworkCore.SqlServer" -o "Models" -f -t "DCUTRANSLATIONS" --use-database-names

CLI --use-database-names Use table and column names directly from the database.

siliond avatar Sep 22 '17 15:09 siliond

Same Issue.

field names are still PascalCaseify

Working with it is impossible.

I need a fix quickly.

BlackBackground avatar Sep 28 '17 16:09 BlackBackground

@BlackBackground Hope this helps, it helped me: use EF vs core if you have the option, it works (table and column names preserved as is) when reverse engineering model: https://msdn.microsoft.com/en-us/library/jj200620(v=vs.113).aspx, see step 3.

siliond avatar Sep 28 '17 16:09 siliond

@siliond Thanks your your answer. Unfortunately your answer doesn't help. The structure must be updated frequently.

BlackBackground avatar Sep 29 '17 07:09 BlackBackground

@BlackBackground Indeed, I don't know how to regenerate again easily besides deleting the model and classes and adding it again.

siliond avatar Sep 29 '17 18:09 siliond

Does the team consider pull requests for fixing something like this?

camelinckx avatar Oct 05 '17 12:10 camelinckx

@camelinckx Absolutely. Please let us know if you're working on it.

ajcvickers avatar Oct 05 '17 16:10 ajcvickers

@ajcvickers I am, testing now, pushing a PR shortly.

chrisAmelinckx avatar Oct 05 '17 18:10 chrisAmelinckx

@ajcvickers https://github.com/aspnet/EntityFrameworkCore/pull/9981

chrisAmelinckx avatar Oct 05 '17 19:10 chrisAmelinckx