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

Switching Model Backend

2 Answers 45 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 2
Ryan asked on 25 Apr 2015, 03:07 AM

Hello. I'm using an database-first entities model connected to SQL Server 2014 in dev, and SQL Azure in production.

Is there an easier way to switch the Backend setting to Azure on deployment?

Currently I have to manually go to the model, right-click Show Model Settings, set the Backend to Azure and save. (Then manually change it back after deploying)

Cheers,

Ryan

2 Answers, 1 is accepted

Sort by
0
Accepted
Simeon Simeonov
Telerik team
answered on 29 Apr 2015, 04:46 PM
Hello Ryan,

Thank you for contacting us.

Yes it is possible to base the model settings on configuration and as a result have different settings for local development and production. This is done by extending the context class for your domain model (the EntitiesModel partial class generated by the Rlinq). How you can do this is explained here. Please note that you will have to add your implementation in the same assembly where your model is and your extension partial class should be with the same name as the context partial class.

In your extension partial class you can extend the CustomizeBackendConfiguration method and in it you can set the Backend settings based on environment configurations. You can set the Backend like this:

public partial class EntitiesModel
{
    static partial void CustomizeBackendConfiguration(ref Telerik.OpenAccess.BackendConfiguration config)
    {
        config.Backend = "Azure";
        //backend.Backend = "MsSql";
    }
}


1/ One possible way to determine programmatically if you are running on local environment or Azure is like this:
public partial class EntitiesModel
{
    static partial void CustomizeBackendConfiguration(ref Telerik.OpenAccess.BackendConfiguration config)
    {
        // Local environment (Azure emulated or unit tests)
        if (RoleEnvironment.IsAvailable == false || RoleEnvironment.IsEmulated)
        {
            backend.Backend = "MsSql";
        }
        // Azure - production environment
        else
        {
            config.Backend = "Azure";
        }
    }
}

Please note that this solution couples your implementation with Azure, so it is advisable to extract that conditional check (is local environment) in an external component which you can replace.

2/ Another solution is to base this code on the Azure configuration store functionality which allows you to set different configurations depending on the platform on which the application is running. How you can do this is explained here and here. You can set different configuration settings in the ServiceConfiguration.Cloud.cscfg and the ServiceConfiguration.Local.cscfg configuration files in your Azure cloud service. Then using the CloudConfigurationManager.GetSetting() method you can resolve the Backend and all other platform dependent settings from that configurations files.

Also please note that your connection string is stored in the App.Config, so it can also be resolved depending on the platform you project is running on.

I hope you find this information helpful. If you have any further questions please don't hesitate to contact us.

Regards,
Simeon Simeonov
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Ryan
Top achievements
Rank 2
answered on 30 Apr 2015, 03:33 AM

Thanks, this works great.

I put the backend into my app config so that it's automatically set to Azure when my web app is published.

static partial void CustomizeBackendConfiguration(ref BackendConfiguration config)
{           
      config.Backend = ConfigurationManager.AppSettings["TelerikDataAccessBackend"];
}

Cheers,

R

Tags
Data Access Free Edition
Asked by
Ryan
Top achievements
Rank 2
Answers by
Simeon Simeonov
Telerik team
Ryan
Top achievements
Rank 2
Share this question
or