<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using XMLA endpoint to copy a dataset but source model is null in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Using-XMLA-endpoint-to-copy-a-dataset-but-source-model-is-null/m-p/3439927#M44563</link>
    <description>&lt;P&gt;I am currently working on utilizing XMLA Endpoint with C# to copy a datamodel that exists in my workspace.&lt;/P&gt;&lt;P&gt;The steps I am following are:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create the new datamodel with a dummy model&lt;/LI&gt;&lt;LI&gt;copy the current model over to the new datamodel.&lt;/LI&gt;&lt;/OL&gt;&lt;UL&gt;&lt;LI&gt;This is where I have issues. When I connect to my existing datamodel in Visual Studios the value for model is 'null'.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Can someone direct me to how I can resolve this? Or do I need to recreate the entire model in code other than copy it?&lt;/P&gt;&lt;P&gt;My goal is to have a template datamodel that I will copy to different workspaces and then modify them from there.&lt;/P&gt;&lt;P&gt;I have been working with the below code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;const string connectString = "powerbi://api.powerbi.com/v1.0/myorg/MYDATAMODEL";
 

static void Main(string[] args) {

    Server server = new Server();
    server.Connect(connectString);
    Model model = server.Databases[0].Model;

 

    string sourceDatabaseName = "DATABASE";
    string DatabaseName = "DATABASE - Copy";

    Database sourceDatabase = server.Databases.GetByName(sourceDatabaseName);

        string newDatabaseName = server.Databases.GetNewName(DatabaseName);
        Database targetDatabase = CreateDatabase(newDatabaseName);
        sourceDatabase.Model.CopyTo(targetDatabase.Model);
        targetDatabase.Model.SaveChanges();

        targetDatabase.Model.RequestRefresh(RefreshType.Full);
        targetDatabase.Model.SaveChanges();

     
     Database CreateDatabase(string DatabaseName)
    {

        string newDatabaseName = server.Databases.GetNewName(DatabaseName);

        var database = new Database()
        {
            Name = newDatabaseName,
            ID = newDatabaseName,
            CompatibilityLevel = 1520,  
            StorageEngineUsed = Microsoft.AnalysisServices.StorageEngineUsed.TabularMetadata,
            Model = new Model()
            {
                Name = DatabaseName + "-Model",
                Description = "A Demo Tabular data model with 1520 compatibility level."
            }
        };

        server.Databases.Add(database);
        database.Update(Microsoft.AnalysisServices.UpdateOptions.ExpandFull);

        return database;
    }

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nullvalue.png" style="width: 478px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/971180iFC1B822E744435F5/image-size/large?v=v2&amp;amp;px=999" role="button" title="nullvalue.png" alt="nullvalue.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2023 12:23:44 GMT</pubDate>
    <dc:creator>Don-Bot</dc:creator>
    <dc:date>2023-09-20T12:23:44Z</dc:date>
    <item>
      <title>Using XMLA endpoint to copy a dataset but source model is null</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Using-XMLA-endpoint-to-copy-a-dataset-but-source-model-is-null/m-p/3439927#M44563</link>
      <description>&lt;P&gt;I am currently working on utilizing XMLA Endpoint with C# to copy a datamodel that exists in my workspace.&lt;/P&gt;&lt;P&gt;The steps I am following are:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create the new datamodel with a dummy model&lt;/LI&gt;&lt;LI&gt;copy the current model over to the new datamodel.&lt;/LI&gt;&lt;/OL&gt;&lt;UL&gt;&lt;LI&gt;This is where I have issues. When I connect to my existing datamodel in Visual Studios the value for model is 'null'.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Can someone direct me to how I can resolve this? Or do I need to recreate the entire model in code other than copy it?&lt;/P&gt;&lt;P&gt;My goal is to have a template datamodel that I will copy to different workspaces and then modify them from there.&lt;/P&gt;&lt;P&gt;I have been working with the below code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;const string connectString = "powerbi://api.powerbi.com/v1.0/myorg/MYDATAMODEL";
 

static void Main(string[] args) {

    Server server = new Server();
    server.Connect(connectString);
    Model model = server.Databases[0].Model;

 

    string sourceDatabaseName = "DATABASE";
    string DatabaseName = "DATABASE - Copy";

    Database sourceDatabase = server.Databases.GetByName(sourceDatabaseName);

        string newDatabaseName = server.Databases.GetNewName(DatabaseName);
        Database targetDatabase = CreateDatabase(newDatabaseName);
        sourceDatabase.Model.CopyTo(targetDatabase.Model);
        targetDatabase.Model.SaveChanges();

        targetDatabase.Model.RequestRefresh(RefreshType.Full);
        targetDatabase.Model.SaveChanges();

     
     Database CreateDatabase(string DatabaseName)
    {

        string newDatabaseName = server.Databases.GetNewName(DatabaseName);

        var database = new Database()
        {
            Name = newDatabaseName,
            ID = newDatabaseName,
            CompatibilityLevel = 1520,  
            StorageEngineUsed = Microsoft.AnalysisServices.StorageEngineUsed.TabularMetadata,
            Model = new Model()
            {
                Name = DatabaseName + "-Model",
                Description = "A Demo Tabular data model with 1520 compatibility level."
            }
        };

        server.Databases.Add(database);
        database.Update(Microsoft.AnalysisServices.UpdateOptions.ExpandFull);

        return database;
    }

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nullvalue.png" style="width: 478px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/971180iFC1B822E744435F5/image-size/large?v=v2&amp;amp;px=999" role="button" title="nullvalue.png" alt="nullvalue.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 12:23:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Using-XMLA-endpoint-to-copy-a-dataset-but-source-model-is-null/m-p/3439927#M44563</guid>
      <dc:creator>Don-Bot</dc:creator>
      <dc:date>2023-09-20T12:23:44Z</dc:date>
    </item>
  </channel>
</rss>

