user3843858
user3843858

Reputation: 331

Create a Azure Analysis Service tabular Model Partition in C#

using AMO how we create azure analysis service Partition using C# code with Azure funcation App Regards, Manish

Upvotes: 0

Views: 1597

Answers (1)

RassaR
RassaR

Reputation: 143

You can add partitions just like columns

            var ds = myDatabaseObject.Model.DataSources.Find("DW Connection");
            ds.Model.Tables.Add(new Table
            {
                Name = "tablename",
                Columns =
                {
                    new DataColumn
                    {
                        Name = "Id",
                        DataType = DataType.Int64,
                        SourceColumn = "Id",
                        SourceProviderType = "BigInt",
                        IsUnique = true,
                        IsKey = true
                    },
                    new DataColumn
                    {
                        Name = "DateId",
                        DataType = DataType.DateTime,
                        SourceColumn = "DateId",
                        FormatString = "General Date",
                        SourceProviderType = "Date"
                    }
                    [...]
                },
                Partitions =
                {
                    new Partition
                    {
                        Name = "Main",
                        DataView = DataViewType.Full,
                        Source = new QueryPartitionSource
                        {
                            DataSource = ds,
                            Query = query
                        }
                    }
                    [...]
                }
            });

Adding or removing partitions is also not a problem. For example this is (more or less) the code i'm using to add partitions with new data

        var partitionName = $"name of partition you want to add";
        var newDataPartition = new Partition
        {
            Name = partitionName,
            DataView = DataViewType.Full,
            Source = new QueryPartitionSource
            {
                DataSource = ds,
                Query = "sql query here"
            }
        };

        if (!table.Partitions.ContainsName(partitionName))
        {
            table.Partitions.Add(newDataPartition);
        }
        db.Update(UpdateOptions.ExpandFull);
        table.Partitions[partitionName].RequestRefresh(RefreshType.Full);
        table.Partitions["Main"].RequestMerge(new List<Partition> { table.Partitions[partitionName] });
        db.Model.SaveChanges();

Upvotes: 1

Related Questions