Search code examples
codefluent

Pivot script file per part?


Is it possible to generate one pivot script file per part in CFE ?

In our model, we imagine using pivot runner to update database later on. In our model we have one part that would be used to instanciate many structures (let's call it "Common"), while having one named "Global" shared accross all those ones.

I would like my producer to generate one pivot file based on the Common part only, thus not having any reference of the Global entities;

Is it achievable ?

Thanks for your answer,


Solution

  • XML parts are storage units. It allows you to split a large model into multiple files, but this doesn't change the inferred model. Producers use the inferred model.

    What I would do is separate entities into different schema, so you'll have two schema: "Common" and "Global". The file generated by the Pivot Script producer will still contain all the objects, but you are able to distinguish them thanks to the schema. Then you can use the PivotRunner and change a little its behavior to only preserve objects in a specific schema:

    // References: CodeFluent.Runtime.dll and CodeFluent.Runtime.Database.dll
    
    PivotRunner runner = new PivotRunner("pivot.xml");
    foreach (var table in runner.Tables.Where(t => t.Schema != "Common").ToList())
    {
        runner.Tables.Remove(table);
    }
    // TODO stored procedures, functions, views, table types, etc.
    
    runner.ConnectionString = "...";
    runner.Run();
    

    http://blog.codefluententities.com/2013/10/10/the-new-sql-server-pivot-script-producer/