แชร์ผ่าน


เปรียบเทียบแบบจําลองความหมายแบบจําลองที่ปรับขนาดออกแบบจําลอง

บทความนี้แสดงตัวอย่างแอป Visual Studio สําหรับการเปรียบเทียบคุณสมบัติของแบบจําลองความหมายเมื่อเปิดใช้งานการปรับมาตราส่วนแบบจําลองความหมายของ Power BI

syncStatus REST API จะแสดงให้เห็นว่าแบบจําลองความหมายแบบอ่าน-เขียนและแบบจําลองแบบอ่านอย่างเดียวซิงค์กันหรือไม่ คุณยังสามารถใช้ Tabular Object Model (TOM) เพื่อสร้างแอปพลิเคชันแบบกําหนดเองที่เชื่อมต่อกับทั้งแบบจําลองความหมาย และเปรียบเทียบการประทับเวลา เมตาดาต้า และผลลัพธ์คิวรีระหว่างกันได้

แอป 1 - ตรวจสอบคุณสมบัติของวัตถุฐานข้อมูล

ใช้โค้ดด้านล่างเพื่อสร้างแอปที่ตรวจสอบ คุณสมบัติ LastUpdate, LastProcessed และ LastSchemaUpdate ของแบบจําลองความหมายของคุณ ก่อนที่แอปจะดําเนินการตรวจสอบ จําเป็นต้องเรียกใช้ Refresh() เมธอด เพื่อรับเมตาดาต้าของแบบจําลอง

แทนที่ <WorkspaceUrl> ด้วย URL <Semantic modelName> ของพื้นที่ทํางานของคุณและด้วยชื่อของแบบจําลองความหมายของคุณ

string workspaceUrl = "<WorkspaceUrl>";  // Replace <WorkspaceUrl> with the URL of your workspace
string datasetName = "<Semantic modelName>";  // Replace <Semantic modelName> with the name of your semantic model 
using (var workspace_readwrite = new Microsoft.AnalysisServices.Tabular.Server()) 
using (var workspace_readonly = new Microsoft.AnalysisServices.Tabular.Server()) 
{
    workspace_readwrite.Connect(workspaceUrl + "?readwrite"); 
    workspace_readonly.Connect(workspaceUrl + "?readonly"); 
    var datasetRW = workspace_readwrite.Databases.FindByName(semantic modelName); 
    var datasetRO = workspace_readonly.Databases.FindByName(semantic modelName); 

    if (datasetRW == null || datasetRO == null) 
    { 
        throw new ApplicationException("Database cannot be found!"); 
    }
    datasetRW.Refresh(); 
    datasetRO.Refresh(); 
    Console.WriteLine($"LastUpdated: {datasetRW.LastUpdate} (readwrite) {datasetRO.LastUpdate} (readonly)"); 
    Console.WriteLine($"LastProcessed: {datasetRW.LastProcessed} (readwrite) {datasetRO.LastProcessed} (readonly)"); 
    Console.WriteLine($"LastSchemaUpdate: {datasetRW.LastSchemaUpdate} (readwrite) {datasetRO.LastSchemaUpdate} (readonly)\n"); 
} 
Console.WriteLine("Test completed. Press any key to exit."); 
Console.Read(); 

แอป 2 - เปรียบเทียบเมตาดาต้าของแบบจําลองความหมาย

ใช้โค้ดด้านล่างเพื่อเปรียบเทียบเมตาดาต้าของแบบจําลองความหมายแบบอ่าน-เขียนหลักกับเมตาดาต้าของแบบจําลองแบบอ่านอย่างเดียว แทนที่ <WorkspaceUrl> ด้วย URL <DatasetName> ของพื้นที่ทํางานของคุณและด้วยชื่อของแบบจําลองความหมายของคุณ

string workspaceUrl = "<WorkspaceUrl>";  // Replace <WorkspaceUrl> with the URL of your workspace 
string datasetName = "<DatasetName>";  // Replace <DatasetName> with the name of your semantic model 
using (var workspace_readwrite = new Microsoft.AnalysisServices.Tabular.Server()) 
using (var workspace_readonly = new Microsoft.AnalysisServices.Tabular.Server()) 
{ 
    workspace_readwrite.Connect(workspaceUrl + "?readwrite"); 
    workspace_readonly.Connect(workspaceUrl + "?readonly"); 
    var datasetRW = workspace_readwrite.Databases.FindByName(datasetName); 
    var datasetRO = workspace_readonly.Databases.FindByName(datasetName); 

    if (datasetRW == null || datasetRO == null) 
    { 
        throw new ApplicationException("Database cannot be found!"); 
    } 

    string tmslRW = Microsoft.AnalysisServices.Tabular.JsonSerializer.SerializeDatabase(datasetRW); 
    string tmslRO = Microsoft.AnalysisServices.Tabular.JsonSerializer.SerializeDatabase(datasetRO); 

    if (tmslRW != tmslRO) 
    { 
        Console.WriteLine("The replicas are out of sync.\n"); 
    } 
    else 
    { 
        Console.WriteLine("The replicas are in sync.\n"); 
    } 
} 
Console.WriteLine("Test completed. Press any key to exit."); 
Console.Read(); 

แอป 3 - คิวรีข้อมูลแบบจําลองความหมาย

ใช้ ADOMD.NET เพื่อคิวรีข้อมูลในแบบจําลอง แทนที่ <WorkspaceUrl> ด้วย URL <DatasetName> ของพื้นที่ทํางานของคุณและด้วยชื่อของแบบจําลองความหมายของคุณ

string workspaceUrl = "<WorkspaceUrl>";  // Replace WorkspaceUrl with the URL of your workspace 
string datasetName = "<DatasetName>";  // Replace DatasetName with the name of your semantic model 
string daxQuery = "Evaluate SUMMARIZECOLUMNS(RefreshTimeTable[Time])"; 
using (var connectionRW = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection()) 
using (var connectionRO = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection()) 
{ 
    connectionRW.ConnectionString = $"Data Source={workspaceUrl}?readwrite;Catalog={datasetName}"; 
    connectionRO.ConnectionString = $"Data Source={workspaceUrl}?readonly;Catalog={datasetName}"; 
    connectionRW.Open(); 
    connectionRO.Open(); 
    var cmd = new Microsoft.AnalysisServices.AdomdClient.AdomdCommand(daxQuery); 
    string resultRW = string.Empty; 
    string resultRO = string.Empty; 
    cmd.Connection = connectionRW; 
    using (var reader = cmd.ExecuteReader()) 
    { 
        while (reader.Read()) 
        { 
            resultRW = reader.GetString(0); 
        } 
    } 

    cmd.Connection = connectionRO; 
    using (var reader = cmd.ExecuteReader()) 
    { 
        while (reader.Read()) 
        { 
            resultRO = reader.GetString(0); 
        } 
    } 

    if (resultRW != resultRO) 
    { 
        Console.WriteLine("The replicas are out of sync.\n"); 
    } 
    else 
    { 
        Console.WriteLine("The replicas are in sync.\n"); 
    } 
} 
Console.WriteLine("Test completed. Press any key to exit."); 
Console.Read();