wp7支持本地数据库了,如下是创建使用本地数据库应用程序的基本方法:
第一步:构建数据上下文
- 添加引用:System.Data.Linq,并在程序中要用到的地方添加如下代码:
using System.Data.Linq; using System.Data.Linq.Mapping; using System.ComponentModel; using System.Collections.ObjectModel;
- 添加数据表实体类:
[Table] public class ToDoItem : INotifyPropertyChanged, INotifyPropertyChanging { // Define ID: private field, public property and database column. private int _toDoItemId; [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)] public int ToDoItemId { get { return _toDoItemId; } set { if (_toDoItemId != value) { NotifyPropertyChanging("ToDoItemId"); _toDoItemId = value; NotifyPropertyChanged("ToDoItemId"); } } } // Define item name: private field, public property and database column. private string _itemName; [Column] public string ItemName { get { return _itemName; } set { if (_itemName != value) { NotifyPropertyChanging("ItemName"); _itemName = value; NotifyPropertyChanged("ItemName"); } } } // Define completion value: private field, public property and database column. private bool _isComplete; [Column] public bool IsComplete { ge