What is the best way to store Units.net quantity in DB? #1513
-
I saw too many approaches to store quantity in Db like storing value and Unit name in db record and convert it to expected quantity with library's methods. |
Beta Was this translation helpful? Give feedback.
Answered by
lipchev
Feb 18, 2025
Replies: 2 comments 3 replies
-
It's an interesting question to which of course there isn't one good answer. Let me try to break-down the different options:
|
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
alirezakamranian
-
Dropped a wiki here, pasting in the above. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's an interesting question to which of course there isn't one good answer. Let me try to break-down the different options:
Value
of the quantity, converted to some base unit (e.g. storing all values asMassUnit.Gram
orVolumeUnit.Milliliter
)- this is probably the only option that can support direct database queries (anything else would require some form of aCASE
switching query on the set of applicable units). This option assumes that the UI is responsible for actually selecting an appropriate display unit for the quantity.{Value, Unit}
pair: this assumes that the user is expecting to see the quantity in the same u…