❔ Display data saved in database in a specified format
Hi, how can i display the value in a specific format than the one saved in database? For example, I have in my database
When retrieving data from the database and showing it in a table, how do I make it display "Level 1", "Level 2", instead of "LevelOne", "LevelTwo"?
3 Replies
Assuming EF, you can always
.Select()
it to new strings
In any case, you can still modify it on the client side, not the database side
You could probably use Humanizer library, in two stages
First humanize the string from LevelTwentySeven
to Level Twenty Seven
Then grab everything besides Level
and de-humanize it to a number
If possible
Or, a better idea... just store it as numbers in the database
Yes, I'm using EF Core. I actually had the values in Enum, and display the values in my dropdown in format like "Level 1", "Level 2". However, I discovered that when user creates like a new location, it saves the value as Enum int like "LevelOne = 0", it saves this "0" in, which is as expected
So I was wondering if it is possible if after converting it to string, I can format the display on client-side
Also, I'm not looking to use more 3rd party library
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.