f# 克隆记录数据

f# Clone Record data

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

我正在学习这个例子。

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

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

您可以稍微修改@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