sivaL
sivaL

Reputation: 1982

How to connect Azure federated root database and apply federation in entity framework?

I tried the following code:

CrmEfEntities dc = new CrmEfEntities(federatedRootDBConnectionString);
string federationCmdText = @"USE FEDERATION Customer_Test_Federation (testId=100) WITH FILTERING=ON, RESET";
dc.ExecuteStoreCommand(federationCmdText);  
var count = dc.Projects.Count();

I got the exception saying - {"Invalid object name 'dbo.Project'."} It connected to the Federated root database. Executed the Federation sql command. But I am not getting the entity object. I'm using EntityFramework 4.0 . Anybody knows this?

Upvotes: 0

Views: 251

Answers (1)

Vitor Tomaz
Vitor Tomaz

Reputation: 81

You have to open the connection before the USE FEDERATION command

using (DemoEntities db = new DemoEntities())
{
   db.Connection.Open();
   string federationCmdText = @"USE FEDERATION ProdutosFed(ID = 110) WITH RESET, FILTERING=OFF";
   db.ExecuteStoreCommand(federationCmdText); 
}

Upvotes: 3

Related Questions