Hi,
I'm currently working on a new project with EF6 (ntityFramework 6.0.0-alpha3) and I encounter a problem with the SQL Azure federations...
According to [this article (2013-01-07)](http://msdn.microsoft.com/en-us/library/windowsazure/hh703245.aspx), I send the USE statement and I open a new transaction:
```
using (TestEntities dc = new TestEntities())
{
((IObjectContextAdapter)dc).ObjectContext.Connection.Open();
dc.Database.ExecuteSqlCommand(@"USE FEDERATION TestFederation (FederationKey=0) WITH FILTERING = OFF, RESET"); // Exception occurs here
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
[.......]
scope.Complete();
}
}
```
With Entity Framework 5 installed, the "USE FEDERATION..." is accepted but with Entity Framework 6 (same code, juste a different version of EF), an exception occurs: "USE FEDERATION statement not allowed within multi-statement transaction."
Anyone has a idea why it does not work?
Thanks in advance!
Comments: Hello, Thanks for raising this issue. We will be discussing it in an upcoming design meeting. In the meanwhile, one possible workaround would be to execute the command on the database connection directly, e.g. (I haven't compiled nor tested this code snippet but something similar should work): ``` var connection = dc.Database.Connection; var command = connection.CreateCommand(); command.CommandText = @"USE FEDERATION TestFederation (FederationKey=0) WITH FILTERING = OFF, RESET"; if (connection.State!=ConnectionState.Open) connection.Open(); command.ExecuteNonQuery(); ``` You may as well encapsulate this in a method that would allow you to switch to different federation member.
I'm currently working on a new project with EF6 (ntityFramework 6.0.0-alpha3) and I encounter a problem with the SQL Azure federations...
According to [this article (2013-01-07)](http://msdn.microsoft.com/en-us/library/windowsazure/hh703245.aspx), I send the USE statement and I open a new transaction:
```
using (TestEntities dc = new TestEntities())
{
((IObjectContextAdapter)dc).ObjectContext.Connection.Open();
dc.Database.ExecuteSqlCommand(@"USE FEDERATION TestFederation (FederationKey=0) WITH FILTERING = OFF, RESET"); // Exception occurs here
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
[.......]
scope.Complete();
}
}
```
With Entity Framework 5 installed, the "USE FEDERATION..." is accepted but with Entity Framework 6 (same code, juste a different version of EF), an exception occurs: "USE FEDERATION statement not allowed within multi-statement transaction."
Anyone has a idea why it does not work?
Thanks in advance!
Comments: Hello, Thanks for raising this issue. We will be discussing it in an upcoming design meeting. In the meanwhile, one possible workaround would be to execute the command on the database connection directly, e.g. (I haven't compiled nor tested this code snippet but something similar should work): ``` var connection = dc.Database.Connection; var command = connection.CreateCommand(); command.CommandText = @"USE FEDERATION TestFederation (FederationKey=0) WITH FILTERING = OFF, RESET"; if (connection.State!=ConnectionState.Open) connection.Open(); command.ExecuteNonQuery(); ``` You may as well encapsulate this in a method that would allow you to switch to different federation member.