在C#中创建Azure Analysis Service表格模型分区

时间:2017-07-19 12:00:42

标签: c# azure azure-functions azure-analysis-services

使用AMO我们如何使用C#代码创建azure分析服务分区 使用Azure功能应用程序 问候, 和Manish

1 个答案:

答案 0 :(得分:1)

您可以像列

一样添加分区
            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
                        }
                    }
                    [...]
                }
            });

添加或删除分区也不是问题。例如,这是(或多或少)我用于添加具有新数据的分区的代码

        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();