Saving weight in a database table

I play with MVC training and want to create a recipe app to store my recipes.

I am using .net with Sql Server 2008 R2, however I do not think it really matters with what I am trying to do.

I want to record all the measures that I use. In my country, we use the metric, but I want people to be able to use the empire with my application.

How can I structure the table to deal with the differences, I thought of storing all the dimensions as an int and having a foreign key to store the type of weight.

Ideally, I would like to be able to share recipes between people and display measurements in my own way.

This is the right way.

IngredientID PK
Weight int
TypeOfWeight int e.g. tsp=1,tbl=2,kilogram=3,pound=4,litre=5,ounce=6 etc
UserID int 

Or is this path disabled? Any suggestions would be great!

+3
2

( ), . typeofweight. -, , ( ).

, TSP, , - : id, , .

, standard -

type   | conversion
gram   | 1
ounce  | 28.35
kg     | 1000
tsp    | 5            // assuming that 1 tsp = 5 grams of water
pound  | 453.59

type   | vol-to-weight
water  | 1
sugar  | 1.4          // i.e. 1 tsp holds 5g of water, but 7g of sugar

500 tsp,

  units x ounce.conversion x sugar.vol-to-weight
= 500   x 28.35            x 1.4

Ingredient is specified as 3 ounces of starch.  Show in grams
= 3 x 28.35    (straightforward isn't it)

Ingredient is specified as 3 ounces of starch.  Show in pounds
= 3 * 28.35 / 453.59
+5

, (Kilo/Pound) .. () "" , . , Imperial, , , . .

, , , ( ),

+6

Source: https://habr.com/ru/post/1787606/


All Articles