2014-03-06 35 views
0

使用Microsoft.AnalysisServices編寫c#應用程序,我想從中檢索我的Cube中的MeasureGroups度量值。獲取與給定度量組關聯的所有度量

下面是代碼:

Server server = new Server(); 
    server.Connect(serverName); 
    Database database = server.Databases.FindByName(databaseName); 
    Cube cube = database.Cubes.FindByName(cubeName); 

在這裏,我有我的魔方,然後:

MeasureGroup sampleMeasureGroup = cube.MeasureGroups[0]; 

然後,我可以簡單地得到與sampleMeasureGroup相關措施:

var measures = sampleMeasureGroup.Measures; 

但在這種情況下,我沒有得到計算的措施,只有標準的措施。有什麼辦法可以得到計算的措施嗎?

回答

0

可以使用低級別的API,它訪問架構行集是這樣的:

AdomdClient.AdomdRestrictionCollection restrColl = new AdomdClient.AdomdRestrictionCollection(); 
restrColl.Add("CUBE_NAME", cube.Name); 
DataSet ds = clientConn.GetSchemaDataSet("MDSCHEMA_MEASURES", restrColl); 
foreach(DataRow row in ds.Tables[0].Rows) { 
    string expr = row.Field<string>("EXPRESSION"); 
    if (string.IsNullOrEmpty(expr)) { 
     // measure is a physical measure 
    } else { 
     // measure is a calculated measure, and 'expr' is its definition 
    } 
    // use other columns like MEASURE_NAME, MEASURE_UNIQUE_NAME, DATA_TYPE, 
    // DEFAULT_FORMAT_STRING ... as you need them 
} 

MDSCHEMA_MEASURES行集列出了包含在立方體的所有措施,並記錄在這裏:http://technet.microsoft.com/en-us/library/ms126250.aspx

相關問題