Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Manipulating semantic models using AMO and TOM libraries

Hi,
my problem is the following. I have a report that should be consumed across countries, but having one large model plus row level security isn't really an option as report would be gargantuan in size.
So I'd like to try to manipulating model (it would be a really small change) and then deploy semantic models using XMLA endpoint.
I am using this C# code, 

using tab = Microsoft.AnalysisServices.Tabular;
using Azure.Identity;
using ac = Azure.Core;
using mas = Microsoft.AnalysisServices.Core;
using ma = Microsoft.AnalysisServices;
using Microsoft.AnalysisServices;





String tenantdId = "myTenantId";

String clientId = "myclientId";

String clientSecret = "myClientSecret"

tab.Server myServer = new tab.Server();
ClientSecretCredential clientSecretCredential = new ClientSecretCredential(tenantId, clientId,
clientSecret);

ac.AccessToken token = clientSecretCredential.GetToken(new ac.TokenRequestContext(new String[]
{ @"https://analysis.windows.net/powerbi/api/.default" }));
ma.AccessToken token1 = new ma.AccessToken(token.Token, token.ExpiresOn);
myServer.AccessToken = token1;
myServer.Connect(@"powerbi://api.powerbi.com/v1.0/myorg/<myWorkspace>");
tab.DatabaseCollection databaseCollection = myServer.Databases;
Console.WriteLine(databaseCollection.Count);
foreach (tab.Database item in databaseCollection) {
      tab.Model model = item.Model;
      if (model != null)
      {
            tab.TableCollection tabCol = model.Tables;
            foreach (tab.Table table in tabCol)
            {
                 Console.WriteLine(table.Name);
            }
      }
}



I am able to connect to server, see semantic model (database object) but although modelType property is Tabular, model property is always NULL, so I am not able to see actual tables and parameters.
My service principal in a member of workspace (not admin), semantic models readWriteMode is set to readWrite, default compatibilty is 1600.
I used the takeover REST API
https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/take-over-in-group
to take over semantic model, and now it does belong to service principal I am using but nothing changed.
Semantic models were created alongside reports using Power BI desktop and then published to Power BI workspace assigned to premium capacity.
Is there anything that I am missing?

0 REPLIES 0

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.