0

I want to map a double property so that I can store its value in SQL Server (Express edition). The default mapping will end up in sql float columns. I want to have DB columns of type decimal(18,6). But my problem is that I can't get it done through Fluent Mapping. Depending on mapping syntax SQL columns are either of type float or decimal(18,0). Here is a summary of what I got:

Map(x => x.Quantity); ---> float

Map(x => x.Quantity).Precision(18).Scale(6); ---> float

Map(x => x.Quantity).CustomSqlType("decimal").Precision(18).Scale(6); ---> decimal(18,0)

How can I set Precision and Scale when I map a double ?

alphanoch
  • 181
  • 1
  • 8
  • is `Quantity` a `decimal` type in your application? – Russ Cam Oct 15 '14 at 10:36
  • No Quantity is double: public double Quantity { get; set; } – alphanoch Oct 15 '14 at 13:27
  • Any reason why you're using a `double` in the application and not a `decimal`? – Russ Cam Oct 15 '14 at 22:34
  • Yes, smaller is faster : see [http://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when](http://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when) – alphanoch Oct 16 '14 at 10:03
  • Well, it depends what you're intending to use it for; what you gain in speed, you lose in precision. Unless you *know* that you really need to use a `double`, using a `decimal` will rectify your mapping problem immediately. Besides, `double` can handle larger numbers than can be stored in a `decimal` type in the database so you have potential overflows to contend with. – Russ Cam Oct 16 '14 at 10:22
  • Thank you for these warnings but what if I do want to have sql columns of types decimal(18,6) ? What's wrong with this Fluent syntax Map(x => x.Quantity).CustomSqlType("decimal").Precision(18).Scale(6); ? – alphanoch Oct 17 '14 at 06:22

0 Answers0