Nested runtime coercion for Nullable double

Say I have a value defined as a form of commission formulas

let address_commission = 1.0 // minimal simplified example

and I want to apply the above commission to the amount that I read from the database (the code from the WCF service window that I have)

let address_commission = 1.0 // minimal simplified example
new Model.ClaimModel( 
  //RequestRow = i, recounting
  Code = (row.["claim_code"] :?> string), 
  EvtDate = (row.["event_date"] :?> DateTime),
  // skipping lines...
  Amount = (row.["amount"] :?> double) * address_commission,

now I see that the amount line compiles fine, but I also need to include the same commission in the next

PrevAmount = (if row.IsNull("prev_amount")  then Nullable()  else  (row.["prev_amount"] :?> Nullable<double>)),

which is wrong since The type 'float' does not match the type 'obj'

Therefore, I also tried

PrevAmount = (if row.IsNull("prev_amount")  then Nullable()  else  (((row.["prev_amount"] :?> double) * address_commission) :?> Nullable<double>)),

but he also fails with The type 'double' does not have any proper subtypes and cannot be used as the source of a type test or runtime coercion.

What is the right way to handle this?

+2
source share
2 answers

:?> , , . , open FSharp.Linq.NullableOperators . ( , - msdn). ?*? . :

let x = System.Nullable<float> 4.
let y = x ?* 3.0
//val y : System.Nullable<float> = 12.0

? .

Nullable float, Option.ofNullable(y) float y.

+2

Nullable(...)

PrevAmount = (if row.IsNull("prev_amount")  then Nullable()  else  Nullable((row.["prev_amount"]  :?> double) * address_commission)),

, - , , .

+1

All Articles