我有以下代码。如果我将线路更改where (row.SiteID = 1)
为where (row.SiteID = 2)
. 我在网上搜索并添加LocalSchemaFile = "Schema.dbml", ForceUpdate = false
了SqlDataConnection
. 每次更改查询条件时,仍然需要大约 15 秒。
更新:
如果我在不更改 Linq 代码的情况下重新运行代码,它将立即从数据库表中获取并打印该行。
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 > // Still take 15 secs
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))
headOrDefault
}
query
[<EntryPoint>]
let main argv =
let aRow = getARow
printfn "%A" aRow
0