Skip to content

What is the best way to store Units.net quantity in DB? #1513

Closed Answered by lipchev
alirezakamranian asked this question in Q&A
Discussion options

You must be logged in to vote

It's an interesting question to which of course there isn't one good answer. Let me try to break-down the different options:

  1. Using a single column for storing the Value of the quantity, converted to some base unit (e.g. storing all values as MassUnit.Gram or VolumeUnit.Milliliter)- this is probably the only option that can support direct database queries (anything else would require some form of a CASE 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.
  2. Using two columns mapped to the {Value, Unit} pair: this assumes that the user is expecting to see the quantity in the same u…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@angularsen
Comment options

@angularsen
Comment options

@alirezakamranian
Comment options

Answer selected by alirezakamranian
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants