0

I'm working on a web-api project created in .NET6 and I'm using Entity Framework Core (6.0) in it. I have already designed Oracle database So I've to use database-first approach for my project. For this purpose, when I try to generate the data-models using EF DBContext Scaffolding with the below command, It successfully generates all the relevant data-models.

dotnet ef dbcontext scaffold "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SKL)));User Id=BOR;Password=myPassword;" Oracle.EntityFrameworkCore -o Models\BOR -c "EF_BORContext" -f --no-onconfiguring

But the issue is that; its generating the data-models having name with first character in upper-case and all other characters are in lower-case. But I want to follow PascalCase for my data-model names.

For example, the generated data-model for one of my entity named as APPGROUP; enter image description here

I want to follow PascalCase convention for my ClassName and ClassPropertiese. Is there any way to fix it? I try to find solution on Google and StackOverflow but couldn't get any fix.

Arsman Ahmad
  • 2,000
  • 1
  • 26
  • 34
  • Post code as *text* not images. Images can't be copied, compiled, tested or googled – Panagiotis Kanavos May 09 '22 at 13:01
  • FYI Entity Framework and Entity Framework *Core* are totally different things, your tags are kind of confusing, you tagged with .NET (Core) 6 but also Entity Framework 6 which doesn't work out, EF 6 is for .NET *Framework* – MindSwipe May 09 '22 at 13:04
  • Furthermore, by using the `database first` approach your telling EF Core to use the names from your database. To fix this you can either rename your tables (and columns) in your database, rename name them in your code and use the EF Core annotations (check [here](https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/data-annotations#table-and-column)) to map them correctly to existing tables, use the [fluent API to do the same](https://stackoverflow.com/a/42191152/9363973) or rename your tables and columns and switch to the `code first` approach – MindSwipe May 09 '22 at 13:10
  • Code from the images doesn't need to be tested. Its just a snapshot which I want to share to have a clear image of problem. @PanagiotisKanavos – Arsman Ahmad May 09 '22 at 14:10
  • You achieved the exact opposite. Post the text instead. You don't need to post the entire class, only the class name and a couple of properties. It's *us* that want to copy and test this code. – Panagiotis Kanavos May 09 '22 at 14:11
  • Thank You @PanagiotisKanavos. I'll keep it in my note for the next time. :-) – Arsman Ahmad May 09 '22 at 14:12
  • Besides, you didn't post the table names. It's unclear whether you want to preserve the original casing or introduce Pascal casing no matter what. I think there are SO answers that show how to use a custom naming convention that uses Humanizer to pascal-case phrases. – Panagiotis Kanavos May 09 '22 at 14:13
  • Hi @MindSwipe Actually It works fine if I use `SQL Server Database` and it follows `PascalCase`. But when I try to generate `data-models` for my `Oracle database`, the naming convention got disturbed. I have hundreds of `tables` and its impossible for me to add `data-annotation` for every table/column for every time. – Arsman Ahmad May 09 '22 at 14:16
  • Have you tried using the `--use-database-names` parameter ? – Panagiotis Kanavos May 09 '22 at 14:17
  • Well, are your tables/ columns named in a PascalCase manner? Because if not, how is EF supposed to figure out what a word is, and what isn't, i.e which letter to capitalise? As Panagiotis Kanavos pointed out, there may be some way to customise the naming EF generates – MindSwipe May 09 '22 at 14:18
  • Yes, I tried `--use-database-names` and it generates all caps. It must follow `C#` rule to follow `PascalCase` for `Class name and Properties`. – Arsman Ahmad May 09 '22 at 14:19
  • You mean the table names are all-caps? Are you asking how to get EF Core to recognize words in unseparated strings and properly case them? Please post the relevant information in the question itself. As Text!. Actual table names, expected names, what you got instead. – Panagiotis Kanavos May 09 '22 at 14:30
  • `SQL Server` follows `PascalCase` in default, that's why it works fine for `SQL Server`. But for `Oracle`, every `table/column` name is in `capital by default`. So it comes with the naming convention issue in `Oracle` and that's why I can't use `--use-database-names`. I hope you understand now! @PanagiotisKanavos – Arsman Ahmad May 09 '22 at 14:37
  • No, SQL Server has no default naming conventions. It *does* preserve the casing you used when creating the table, but that's not significant. You still haven't posted the necessary information. It's not about whether others understand you, you need to provide enough information so others don't have to guess. I've worked with both Oracle and SQL Server for years, I know about their quirks, but I still can't understand what you expect. If Oracle returns `THISISATABLENAME` why do you expect any library to convert that to `ThisIsATableName` ? Or should it be `ThisIsaTableName`? That's not trivial – Panagiotis Kanavos May 09 '22 at 14:46
  • If that's what you ask, this requires natural language processing. Even if you used a library like [Humanizer](https://github.com/Humanizr/Humanizer) you wouldn't be able to convert `THISISATABLENAME`. It's another matter if the object has distinct eg `THIS_IS_A_TABLE_NAME` or `"THIS IS A TABLE NAME"` – Panagiotis Kanavos May 09 '22 at 14:54

0 Answers0