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.
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.
-
|
Dropped a wiki here, pasting in the above. |
Beta Was this translation helpful? Give feedback.
It's an interesting question to which of course there isn't one good answer. Let me try to break-down the different options:
Valueof the quantity, converted to some base unit (e.g. storing all values asMassUnit.GramorVolumeUnit.Milliliter)- this is probably the only option that can support direct database queries (anything else would require some form of aCASEswitching 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…