2012-11-20 34 views
0

我能夠獲得一段代碼以在.fsx腳本中運行。我從來沒有看到它循環播放我正在拉回的曲目數據。所以我想我會把它放在一個.fs文件中並編譯它。我遇到了兩個問題。 F#IDE強調了type關鍵字和let query =行中的let。這是我的oode(下)我在哪裏關於語法?類型提供程序問題 - 主入口點 - 語法

open System 
open System.Data 
open System.Data.Linq 
open Microsoft.FSharp.Data.TypeProviders 
open Microsoft.FSharp.Linq 

[<EntryPoint>] 
let main argv = 
    type dbSchema = SqlDataConnection<"Data Source=SQLDEV;Initial Catalog=CDDB;Integrated Security=SSPI;"> 
      let db = dbSchema.GetDataContext() 
      // Enable the logging of database activity to the console. 
      db.DataContext.Log <- System.Console.Out 
      let query1 = 
       query { 
        for row in db.SoundRecording do 
        select row 
        take 50 
       } 
      query1 |> Seq.iter (fun row -> printfn "%s - %s" row.DisplayArtist row.DisplayTitle) 
      0 // return an integer exit code 

回答

2

這可能工作 - 你不能在函數內部類型定義

open System 
open System.Data 
open System.Data.Linq 
open Microsoft.FSharp.Data.TypeProviders 
open Microsoft.FSharp.Linq 
type dbSchema = SqlDataConnection<"Data Source=SQLDEV;Initial Catalog=CDDB;Integrated Security=SSPI;"> 
[<EntryPoint>] 
let main argv = 

      let db = dbSchema.GetDataContext() 
      // Enable the logging of database activity to the console. 
      db.DataContext.Log <- System.Console.Out 
      let query1 = 
       query { 
        for row in db.SoundRecording do 
        select row 
        take 50 
       } 
      query1 |> Seq.iter (fun row -> printfn "%s - %s" row.DisplayArtist row.DisplayTitle) 
      0 // return an integer exit code