f#克隆记录数据

时间:2016-02-09 13:39:00

标签: f# f#-data

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

我跟随这个例子。

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

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

1 个答案:

答案 0 :(得分:3)

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