Database doesn't save (writen) in Isolate storage ?

Mar 19, 2012 at 7:00 PM

Hello, I just use Sterling(lastest version 1.5) in my sample windows phone app and I noticed that my app's Isolate storage have nothing after I register database or saving object. But app run fine, debug show that item can be loaded and display. But if I close app than open it again and try to load, it return null.

 

My code:

in App.xaml.cs

Database = Stengine.SterlingDatabase.RegisterDatabase<RecipeDatabase>();

_________________________

in MainPage.xaml.cs

SingleRecipe simpleRecipe = new SingleRecipe(1, "VN food", "notbad", "luch", "fry", "rice", "Vietnam");

SingleRecipe b = App.Database.Load<SingleRecipe>(Convert.ToUInt32(1)); // return null every time ( event if simpleRecipe is saved after app's first run )

var key = App.Database.Save(simpleRecipe);  // return 1, first item

_________________________

 

namespace Cook_Master.Database
{
    public class RecipeDatabase : BaseDatabaseInstance
    {
        /// <summary>
        ///     Data base name
        /// </summary>
        public const string STERLING_RECIPES = "Sterling Recipes";

        /// <summary>
        ///     Indexs on recipe names
        /// </summary>
        public const string IDX_RECIPE_NAME = "IDX_RecipeModel_RecipeName";
        public const string IDX_RECIPE_DETAIL = "IDX_RecipeModel_RecipeDetail";
        public const string IDX_RECIPE_TIME = "IDX_RecipeModel_RecipeTime";
        public const string IDX_RECIPE_METHOD = "IDX_RecipeModel_RecipeMethod";
        public const string IDX_RECIPE_NATION = "IDX_RecipeModel_RecipeNation";
        public const string IDX_RECIPE_INTEGRATION = "IDX_RecipeModel_RecipeIntegration";

        /// <summary>
        ///     Sets up the tables and corresponding keys
        /// </summary>
        /// <returns></returns>
        protected override List<ITableDefinition> RegisterTables()
        {
            return new List<ITableDefinition>
            {
                // recipe
                /*
                    Id = id;
                    Name = name;
                    Detail = detail;
                    Time = time;
                    Method = method;
                    Integration = integration;
                    Nation = nation;
                 */
                CreateTableDefinition<SingleRecipe, uint>(r => r.Id)
                    .WithIndex<SingleRecipe, string, uint>(IDX_RECIPE_NAME, r => r.Name)
                    .WithIndex<SingleRecipe, string, uint>(IDX_RECIPE_TIME, r => r.Detail)
                    .WithIndex<SingleRecipe, string, uint>(IDX_RECIPE_NATION, r => r.Nation)
                    .WithIndex<SingleRecipe, string, uint>(IDX_RECIPE_METHOD, r => r.Method)
                    .WithIndex<SingleRecipe, string, uint>(IDX_RECIPE_INTEGRATION, r => r.Integration)
            };
        }

        /// <summary>
        ///     Database name
        /// </summary>
        public override string Name
        {
            get { return STERLING_RECIPES; }
        }


        public static void CheckAndCreate(ISterlingDatabaseInstance database)
        {
           
        }
    }
}

Mar 19, 2012 at 7:11 PM

nvm, I just figured it out by looking into the sample code:

 

this line:

Database = Stengine.SterlingDatabase.RegisterDatabase<RecipeDatabase>();

must be changed to:

Database = Stengine.SterlingDatabase.RegisterDatabase<RecipeDatabase>(new IsolatedStorageDriver());