3

我试图让 LINQ 在我的 F# 应用程序中正常工作(基于http://msdn.microsoft.com/en-us/library/hh361033.aspx上的文章)。但是,似乎缺少某些属性和功能。

例如,如果我尝试添加以下行:

db.DataContext.Log <- System.Console.Out

我收到一条错误消息:未定义字段、构造函数或成员“日志”。

同样,缺少诸如 InsertOnSubmit 和 InsertAllOnSubmit 之类的函数。我已经设法查询数据库,但是如果这些功能丢失,我现在无法插入任何东西。

示例代码:

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

type internal dbSchema = SqlEntityConnection<"Data Source=localhost;Initial catalog=testDb;Integrated Security=SSPI;">

[<EntryPoint>]
let main argv = 

    let db = dbSchema.GetDataContext()
    db.DataContext.Log <- System.Console.Out // Failure: Log not defined.
    let names = [|"Foo"; "Bar"|]
    let newVals = 
        [ for name in names -> new dbSchema.ServiceTypes.Items(Name = name) ]

    db.Items.InsertAllOnSubmit(newVals) // Same with InsertAllOnSubmit.

    0

我在这里能错过什么?

4

1 回答 1

3

@mydogisbox 好的,这里是:

在行中:

type internal dbSchema = SqlEntityConnection<"Data Source=localhost;Initial catalog=testDb;Integrated Security=SSPI;">

尝试使用SqlDataConnection而不是SqlEntityConnection. 那应该行得通。

于 2013-07-27T03:49:21.350 回答