我有以下 F# 代码。函数getARow
返回(string * string * string) option
。在主函数中,我需要提取列值并将它们a, b, c
分别分配给它们。如何实施?(新手问题)
如果没有找到行,该函数可能会返回 null 吗?如果getARow
返回null如何处理?
open System
open System.Data
open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq
open System.Net
open System.IO
open FSharp.Data
type dbSchema = SqlDataConnection<"Data Source=Svr;Initial Catalog=DB;Integrated Security=SSPI;">
//, LocalSchemaFile = "Schema.dbml", ForceUpdate = false >
let getARow =
let db = dbSchema.GetDataContext()
db.DataContext.Log <- System.Console.Out
let query = query {
for row in db.Table1 do
where (row.SiteID = 1)
select (Some(row.Col1, row.Col2, row.Col2)) // All Colx are strings
headOrDefault // May return null
}
query
[<EntryPoint>]
let main argv =
let aRow = getARow
printfn "%A" aRow
let a,b,c = match aRow with
| ........ // How to let a = Col1, b = Col2 and c = Col3?
| None -> failwith "Cannot find a row" // Null?
0