Quantcast
Channel: Http Client Protocol Issues (and other fun stuff I support)
Viewing all articles
Browse latest Browse all 140

Always Drop and Create Local Database .NET Backend for Azure Mobile Services

$
0
0

In my early testing I wanted to always seed my Local Database.  By default the db was only dropped and reseeded if you changed the models.  There is a simple code change to do this.

In WebApiConfig.cs change the class implementing IDatabaseInitializer that you pass into Database.SetInitializer from DropCreateDatabaseIfModelChanges to DropCreateDatabaseAlways

Example

Previous (only updated if DataObject schema changes):

public static class WebApiConfig{public static void Register()
        {// Use this class to set configuration options for your mobile serviceConfigOptions options = new ConfigOptions();// Use this class to set WebAPI configuration optionsHttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));// To display errors in the browser during development, uncomment the following
            // line. Comment it out again when you deploy your service for production use.
            // config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;Database.SetInitializer(new MobileService3Initializer());
        }
    }public class MobileService3Initializer : DropCreateDatabaseIfModelChanges<MobileService3Context>
    {protected override void Seed(MobileService3Context context)
        {

Now (always recreates the Database and reseeds):

 

public static class WebApiConfig{public static void Register()
        {// Use this class to set configuration options for your mobile serviceConfigOptions options = new ConfigOptions();// Use this class to set WebAPI configuration optionsHttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));// To display errors in the browser during development, uncomment the following
            // line. Comment it out again when you deploy your service for production use.
            // config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;Database.SetInitializer(new MobileService3Initializer());
        }
    }public class MobileService3Initializer : DropCreateDatabaseAlways<MobileService3Context>
    {protected override void Seed(MobileService3Context context)
        {

Viewing all articles
Browse latest Browse all 140

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>