Table of Contents

显示数据源依赖项

脚本用途

此脚本会输出引用所选显式(旧版)数据源的表。这将更容易确定所选数据源的使用位置。

脚本

显示数据源依赖项

//The script outputs the tables that reference the selected explicit (legacy) data source.
if (Model.DataSources.Count == 0)
{
    Info("This model doesn't contain any data sources, it is either empty or using implicit datasources");
    return;
}
// Checks that a data source is selected
DataSource selectedDatasource = null;

if (Selected.DataSources.Count == 1)
    selectedDatasource = Selected.DataSource;
else
    selectedDatasource = SelectObject<DataSource>(Model.DataSources, null, "Select which datasource to see dependencies for");

// Legacy sources
var legacyTables = Model.Tables.Where(t => t.Source == selectedDatasource.Name).ToList();

// M sources
var mTables = Model.Tables.Where(t => t.Partitions.Any(p => p.Expression.Contains($"= #\"{selectedDatasource.Name}\","))).ToList();

// join arrays
var allTables = legacyTables.Union(mTables).OrderBy(t => t.Name);

// Present result
var tableString = string.Join("\r\n", allTables.Select(t => t.Name));
Info($"Datasource {selectedDatasource.Name} is referenced from the following tables:\r\n" + tableString);

说明

此代码片段会获取所选数据源,并遍历模型,找出使用该数据源的分区。

输出示例

Example of the dialog pop-up that informs the user which tables use the selected data source
图 1:弹出对话框示例,用于告知用户哪些表使用了所选数据源。