简体   繁体   English

F#项目花费大量时间来构建

[英]F# project is taking so much time to build

I have created f# solution and added one class library. 我创建了f#解决方案,并添加了一个类库。 Only one project in the solution and 5 files and 20 lines of code in each file. 解决方案中只有一个项目,每个文件中有5个文件和20行代码。 Still it will take more 2 minutes to build each time. 每次构建仍需要2分钟以上的时间。

I have tried to clean solution. 我试图清洁溶液。 Also created new solution and project and includes same files, still it will take same time to build it. 还创建了新的解决方案和项目,并包含相同的文件,但是仍然需要花费相同的时间来构建它。

Note : First I have created it as a Console Application then convert it into the Class Library. 注意 :首先,我将其创建为控制台应用程序,然后将其转换为类库。

Edit: Code Sample ` 编辑:代码示例

open System open Configuration open DBUtil open Definitions 打开系统打开配置打开DBUtil打开定义

module DBAccess = 模块DBAccess =

let GetSeq (sql: string) =
      let db = dbSchema.GetDataContext(connectionString)  
      db.DataContext.CommandTimeout <- 0                        
      (db.DataContext.ExecuteQuery(sql,""))


let GetEmployeeByID (id: EMP_PersonalEmpID) = 
    GetSeq (String.Format("EXEC [EMP_GetEntityById] {0}",id.EmployeeID)) |> Seq.toList<EMP_PersonalOutput>

let GetEmployeeListByIDs (id : Emp_PersonalInput) = 
    GetSeq (String.Format("EXEC [EMP_GetEntityById] {0}",id.EmployeeID)) |> Seq.toList<EMP_PersonalOutput>`

configuration code snippets : `open Microsoft.FSharp.Data.TypeProviders 配置代码段:`open Microsoft.FSharp.Data.TypeProviders

module Configuration = let connectionString = System.Configuration.ConfigurationManager.ConnectionStrings.["EmpPersonal"].ConnectionString 模块配置= let connectionString = System.Configuration.ConfigurationManager.ConnectionStrings。[“ EmpPersonal”]。ConnectionString

//for database,then stored procedure, the getting the context,then taking the employee table
type dbSchema =  SqlDataConnection<"", "EmpPersonal">
//let db = dbSchema.GetDataContext(connectionString)

type tbEmpPersonal = dbSchema.ServiceTypes.EMP_Personal`

Okay, seeing your actual code, I think the main problem is that the type provider connects to the database every time to retrieve the schema. 好的,看到您的实际代码,我认为主要的问题是类型提供程序每次都连接到数据库以检索架构。 The way to fix this is to cache the schema in a dbml file. 解决此问题的方法是将模式缓存在dbml文件中。

type dbSchema = SqlDataConnection<"connection string...",
                                  LocalSchemaFile = "myDb.dbml",
                                  ForceUpdate = false>

The first time, the TP will connect to the database as usual, but it will also write the schema to myDb.dbml . TP会像往常一样第一次连接到数据库,但也会将架构写入myDb.dbml On subsequent compiles, it will load the schema from myDb.dbml instead of connecting to the database. 在后续编译中,它将从myDb.dbml加载架构,而不是连接到数据库。

Of course, this caching means that changes to the database are not reflected in the types. 当然,这种缓存意味着对数据库的更改不会反映在类型中。 So every time you need to reload the schema from the database, you can set ForceUpdate to true , do a compile (which will connect to the db), and set it back to false to use the updated myDb.dbml . 因此,每次需要从数据库重新加载架构时,都可以将ForceUpdate设置为true ,进行编译(将连接到db),然后将其设置为false以使用更新的myDb.dbml

Edit: you can even commit the dbml file to your source repository if you want. 编辑:如果需要,您甚至可以将dbml文件提交到源存储库。 This will have the additional benefit to allow collaborators who don't have access to a development version of the database to compile the solution anyway. 这将带来额外的好处,使无法访问数据库开发版本的协作者无论如何都可以编译解决方案。

关于NGEN的答案曾经帮助过我一次,但是与C#相比,F#的构建时间仍然很糟糕,而不仅仅是几分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM