This is a migrated thread and some comments may be shown as answers.

Multi-tenant in SQL Azure using federation

2 Answers 74 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mike
Top achievements
Rank 1
Mike asked on 26 Apr 2012, 06:57 PM
I'm doing some experiments on using SQL Azure federations to enable muti-tenancy in a web app with Openaccess. The main thing I'm trying to accomplish is making sure to run
string federationCmdText = String.Format(@"USE FEDERATION FED_1 (TenantID={0}) WITH FILTERING=ON, RESET", tenantID);
context.ExecuteNonQuery(federationCmdText);
on every connection, before any subsequent queries on that connection are executed.
How can I accomplish this with Openaccess?

Thanks,
Mike

2 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 27 Apr 2012, 10:58 AM
Hello Mike,
You can set SQL statements that are executed whenever we open a new connection. The list is bound to the backend configuration in your generated context class.

Please add a partial class to your generated context class, override OnDatabaseOpen and add your string to

backendConfiguration.ConnectionPool.InitSQL.Add("...");

Greetings,
Jan Blessenohl
the Telerik team
Follow @OpenAccessORM Twitter channel to get first the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Mike
Top achievements
Rank 1
answered on 27 Apr 2012, 10:15 PM
Worked great thank you. This is what I ended up doing:

public partial class EntitiesModel
    {
 
        Guid tenantID;
         
        public EntitiesModel(Guid TenantID)
            : base(connectionStringName, backend, metadataSource)
        {
            this.tenantID = TenantID;
        }
 
        protected override void OnDatabaseOpen(Telerik.OpenAccess.BackendConfiguration backendConfiguration, Telerik.OpenAccess.Metadata.MetadataContainer metadataContainer)
        {
 
            string federationCmdText = String.Format(@"USE FEDERATION FED_1 (TenantID='{0}') WITH FILTERING=ON, RESET", tenantID.ToString());
            backendConfiguration.ConnectionPool.InitSQL.Add(federationCmdText);
 
            base.OnDatabaseOpen(backendConfiguration, metadataContainer);
 
        }
 
    }

Tags
Development (API, general questions)
Asked by
Mike
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Mike
Top achievements
Rank 1
Share this question
or