08,Windows Phone 本地存储
来源:互联网 发布:什么软件可以男变女 编辑:程序博客网 时间:2024/06/05 08:59
内容预告:
- Windows Phone 的数据库支持
- LINQ to SQL
- 性能和最佳实践
LINQ to Everything:
支持复杂的结构:
支持外键:
WebService缓存:
本地存储:
架构:
对象:
定义表:
// Define the tables in the database [Table] public class Wine : INotifyPropertyChanged, INotifyPropertyChanging { private string wineID; private string name; [Column(IsPrimaryKey=true)] public string WineID { get { return wineID; } set { InvokePropertyChanging(new PropertyChangingEventArgs("WineID")); wineID = value; InvokePropertyChanged(new PropertyChangedEventArgs("WineID")); } } [Column] public string Name { ... } ...}
定义数据上下文:
// Define the data context.public partial class WineDataContext : DataContext {public Table<Wine> Wines;public Table<Vineyard> Vineyards;public WineDataContext(string connection) : base(connection) { }}...// Create the database from data context, using a connection stringDataContext db = new WineDataContext("isostore:/wineDB.sdf");if (!db.DatabaseExists()) db.CreateDatabase();
用SQLMetal代码生成工具:
c:\>Sqlmetal /code:northwindEntities.cs /context:NorthwindDataContext /pluralize northwind.sdf
查询:
// Create the database form data context, using a connection string DataContext db = new WineDataContext("isostore:/wineDB.sdf"); // Find all wines currently at home, ordered by date acquired var q = from w in db.Wines where w.Varietal.Name == “Shiraz” && w.IsAtHome == true orderby w.DateAcquired select w;
插入,更新,删除:别忘了submitChanges
插入:
Wine newWine = new Wine{WineID = “1768",Name = “Windows Phone Syrah",Description = “Bold and spicy"};db.Wines.InsertOnSubmit(newWine);db.SubmitChanges();
更新:
Wine wine = (from w in db.Wines where w.WineID == “1768" select w).First();wine.Description = “Hints of plum and melon";db.SubmitChanges();
删除:
var vineyardsToDelete = from Vineyards v in db.Vineyardswhere v.Country == “Australia”select v;db.Vineyards.DeleteAllOnSubmit(vineyardsToDelete); db.SubmitChanges();
更新数据库结构:
WineDataContext wineDC = new WineDataContext(App.WineDBConnectionString);DatabaseSchemaUpdater dsu = wineDC.CreateDatabaseSchemaUpdater();if (dsu.DatabaseSchemaVersion == 1){dsu.AddColumn<Wine>("BottleType");dsu.DatabaseSchemaVersion = 2;dsu.Execute();}
性能和最佳实践:
- 保持修改的集合很小,换句话说,尽早提交修改,以避免程序终止时数据丢失。
- 用后台线程。
- 优化只读查询。
- 提前填充大量数据。
- 用对的工具,大量复杂的数据用数据库,小数据用独立存储。
- 08,Windows Phone 本地存储
- Windows Phone 7的本地存储——IsolatedStorageSettings
- Windows Phone的本地存储——IsolatedStorageSettings
- Windows Phone的本地存储——IsolatedStorageFile
- Windows Phone 7独立存储之本地数据库
- Windows Phone 独立存储
- windows phone:独立存储
- Windows Phone读取本地数据
- windows phone:使用本地数据库
- [windows phone开发]本地相册
- Windows Phone 7独立存储
- 独立存储, windows phone IsolatedStorageFile
- Windows Phone本地数据库性能最佳实践
- Windows Phone 7 使用本地数据库
- windows phone:本地实现toast通知提醒
- Windows Phone 7使用本地数据库
- Windows Phone——本地数据库
- Windows Phone 8 本地代码实现游戏
- 05,WP8的文件和存储
- .NET 性能测试工具 -- 性能计数器
- .NET 性能测试工具 -- 事件跟踪器(ETW)
- 06,Windows Phone 8程序的生命周期
- 07,Windows Phone后台代理
- 08,Windows Phone 本地存储
- Can not connect to your phone. Disconnect it, restart it, then try connecting again
- 分享一些最近在看的电子书
- word2007页面设置——首页不编码
- 云管理之虚拟化-Xen简介
- 棋类游戏
- 黑马程序员_面向对象学习总结(二)
- Mysql数据库操作常用命令
- Android与服务器端数据交互(基于SOAP协议整合android+webservice)