f# 克隆记录数据

标签 f# f#-data

我正在编写一个脚本来将数据从一个数据库服务器移动到另一个数据库服务器。一次一张 table 对我来说有好处。我已经删除了所有外键等。

我正在遵循这个例子。

http://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work-4/#sql-etl

问题是我不想转换数据,我只想复制它。但我有很多表,每个表都有很多列。在不映射每个单独字段的情况下从一个记录映射到另一个记录的简单方法是什么?

最佳答案

您可以稍微修改@Petr引用的脚本来复制指定的表而不是所有表。请参阅下面的示例。

// Start of modifications here

// Create an array of objects in this case tables to copy
let tablesToCopy = 
    sourceDatabase.Tables 
    |> Seq.cast<Table> // Convert TableCollection to seq<Table> so can use Seq functions
    |> Seq.filter (fun table -> [| "DimTime"; "DimCategory" |] |> Seq.exists (fun tableName -> tableName = table.Name)) 
    |> Seq.toArray // Materialise to an Array so it can be consumed by an ArrayList constructor and assigned to the ObjectList property

let transferDatabase = 
    Transfer(sourceDatabase, 
        CopyAllObjects = false, // Set to false
        CopyAllSchemas = true, 
        CopyAllUserDefinedDataTypes = true, 
        CopyAllTables = false, // Set to false
        ObjectList = System.Collections.ArrayList(tablesToCopy), // Include a list of objects to copy - uses old style ArrayList
        CopyData = true, 
        CopyAllStoredProcedures = true,
        DestinationServer = destServer.Name,
        DestinationDatabase = destDatabase.Name)

// End of modifications here

关于f# 克隆记录数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35293520/

相关文章:

f# - MailboxProcessor - 告诉何时停止?

f# - 如何在 VS 2015 中使用 FSharp.Data?

f# - 是否可以为链接数据编写 F# 类型提供程序?

反射以了解属性是否为选项类型

c# - 如何将此 C# 函数转换为 F# 函数

unit-testing - 如何保证 FsCheck 的重现性

f# - 不使用模运算符 F# 计算余数

f# - CSV 类型提供程序在 F# 交互式中找不到列

F#.Data HTML 解析器从节点提取字符串

f# - Json类型提供程序: using type as an argument in a function