Windows phone LocalDataBase 数据结构发生变化

Changing the database schema
Changes to your Windows Phone app may require changes to your local database schema. Any changes to your local database schema begin with changing the object model of the corresponding data context. TheMicrosoft.Phone.Data.Linq namespace provides theDatabaseSchemaUpdater class to help with database schema changes. For an example of how to use this class, seeWalkthrough: Updating a local database app for Windows Phone.
The DatabaseSchemaUpdater class can perform additive changes to the database, such as adding tables, columns, indexes or associations. For more complex changes, you will need to create a new database and copy the data to the new schema, as applicable. The DatabaseSchemaUpdater class provides aDatabaseSchemaVersion property that you can use to programmatically distinguish different versions of your database.
Important noteImportant Note:
The database does not change to reflect updates from the DatabaseSchemaUpdater object until theExecute method is called. When that method is called, all changes are submitted to the local database as a single transaction, including version updates. Using a single transaction helps the database maintain integrity, such as in cases where the user exits the app during an upgrade.
The following example demonstrates using the DatabaseSchemaUpdater class to modify the database based on theDatabaseSchemaVersion property.
using (ToDoDataContext db = new ToDoDataContext(("isostore:/ToDo.sdf")))
{
        //Create the database schema updater
        DatabaseSchemaUpdater dbUpdate = db.CreateDatabaseSchemaUpdater();


        //Get database version
        int dbVersion = dbUpdate.DatabaseSchemaVersion;


        //Update database as applicable
        if (dbVersion < 5)
        {   //Copy data from existing database to new database 
            MigrateDatabaseToLatestVersion();
        }
        else if (dbVersion == 5)
        {   //Add column to existing database to match the data context
            dbUpdate.AddColumn<ToDoItem>("TaskURL");
            dbUpdate.DatabaseSchemaVersion = 6;
            dbUpdate.Execute();
        }
}




还有方法这样描述:
 
 // Prepopulate the categories.
                   // db.Categories.InsertOnSubmit(new ToDoCategory { Name = "Home" });
                    //db.Categories.InsertOnSubmit(new ToDoCategory { Name = "Work" });
                   // db.Categories.InsertOnSubmit(new ToDoCategory { Name = "Hobbies" });


                    // Save categories to the database.
                   // db.SubmitChanges();


                 
Note:Any files saved in the local folder, including local database files, are not altered during the app update process.


截取自:http://msdn.microsoft.com/zh-cn/library/hh202860
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值