Hi,
there is one thing in F# that is really confusing when it comes to floating point types. The F# float type corresponds to System.Double (double in C#). The System.Single (float in C#) type is called float32 in F#.

This means that the "GetFloat" method actually returns float32. I'm not exactly sure how SQL data types map to .NET types, but I think that using "GetFloat" and then working with "float32" values should work. In that case, you'd get an array<float32> as the result (even without using Array.map).

If you wanted to convert a value of "float32" type to a value of "float" type, then you can use "float" function (which has the same name as the target type and works for various input types):

1
2
3
4
5
6
7
8
 
let double = 1.0
let single = float32(double)
let double2 = float(single)

input |> Array.map(fun x -> float(x)) // converts input (array<float32>) to array<float>
// More simply:
input |> Array.map float // converts input (array<float32>) to array<float>
By on 1/13/2010 12:30 PM ()

Hello, Gary:
Do you have any code sample for LINQ 2 SQL for F# for my question?
By the way, reader.Getfloat(0) didn't work.
Thanks,

By on 1/13/2010 12:49 PM ()

I have already shown the code in another thread.

DataContext.translate()

it converts any sqlreader result sets to array of strong types using column name to property name mapping. you only need to define your strong type with the proper properties(and I said in this case, C# is actually better as it is shorter and cleaner). They are effectively your n-tuples but accessed with property rather than position.

that means 95% of the use cases.

By on 1/13/2010 1:05 PM ()

data conversion is hard, you need to cater for all the possible data type found in SQL server and map them properly to .NET type.

You need lots of reflection coding to handle them properly and that at the moment is too much for you.

Leave this task to others, LINQ 2 SQL has already done it for you.

By on 1/13/2010 12:05 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper