How to write FirstOrDefault Linq Query in F#? Can I use linq to sql in F# in totally?
+5
A:
Note that a more idiomatic approach within F# would probably be to use something along the lines of Seq.tryFind
rather than to use the LINQ operators, although it's not a drop in replacement since it returns an option value.
kvb
2010-05-06 20:53:16
I would also recomend using `Seq.tryFind` - in F#, you generally try to aviod using `null` values (because they are dangerous). Handling option values is easier as you can also use `Option.map` and other functions for working with them (though, this probably won't work in F# LINQ to SQL)
Tomas Petricek
2010-05-06 21:06:35
Yep, `Seq.tryFind (fun _ -> true)` works great.
Joel Mueller
2010-05-06 21:36:48