我现在想在WP8的本地数据库建立我的两张表,具体代码如下:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 5 using System.Text; 6 using System.Threading.Tasks; 7 8 //这是我们的表情值的表 9 using System.ComponentModel; 10 using System.Data.Linq; 11 using System.Data.Linq.Mapping; 12 13 namespace MoonPet 14 { 15 #region 第一张表 16 [Table] 17 public class Moon : INotifyPropertyChanged, INotifyPropertyChanging 18 { 19 private int _moonId; 20 [Column(DbType = "INT IDENTIEY NOT NULL", CanBeNull = false, IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] 21 public int MoonId 22 { 23 get { return _moonId; } 24 set { if (value != _moonId) { OnPropertyChanging("MoonId"); _moonId = value; OnPropertyChanged("MoonId"); } } 25 } 26 private float _moonValue; 27 [Column] 28 public float MoonValue 29 { 30 get { return _moonValue; } 31 set { if (value != _moonValue) { OnPropertyChanging("MoonValue"); _moonValue = value; OnPropertyChanged("MoonValue"); } } 32 } 33 private int _year; 34 [Column] 35 public int Year 36 { 37 get { return _year; } 38 set { if (value != _year) { OnPropertyChanging("Year"); _year = value; OnPropertyChanged("Year"); } } 39 } 40 private int _month; 41 [Column] 42 public int Month 43 { 44 get { return _month; } 45 set { if (value != _month) { OnPropertyChanging("Month"); _month = value; OnPropertyChanged("Month"); } } 46 } 47 private int _day; 48 [Column] 49 public int Day 50 { 51 get { return _day; } 52 set { if (value != _day) { OnPropertyChanging("Day"); _day = value; OnPropertyChanged("Day"); } } 53 } 54 #region 事件和方法 55 public event PropertyChangingEventHandler PropertyChanging; 56 public event PropertyChangedEventHandler PropertyChanged; 57 protected void OnPropertyChanging(string propertyName) 58 { 59 if (PropertyChanging != null) 60 { 61 PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); 62 } 63 } 64 protected void OnPropertyChanged(string propertyName) 65 { 66 if (PropertyChanged != null) 67 { 68 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 69 } 70 } 71 #endregion 72 } 73 #endregion 74 #region 第二张表 75 [Table] 76 public class Diarys : INotifyPropertyChanging, INotifyPropertyChanged 77 { 78 //定义我的实体数据类 79 string _Content; 80 string _CreateTime; 81 string _Title; 82 int _Id; 83 [Column(DbType = "INT IDENTITY NOT NULL", IsPrimaryKey = true, CanBeNull = false, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] 84 85 public int Id 86 { 87 get { return _Id; } 88 set { if (value != _Id) { OnPropertyChanging("Id"); _Id = value; OnPropertyChanged("Id"); } } 89 } 90 [Column] 91 public string Content 92 { 93 get { return _Content; } 94 set { if (value != _Content) { OnPropertyChanging("Content"); _Content = value; OnPropertyChanged("Content"); } } 95 } 96 [Column] 97 public string CreateTime 98 { 99 get 100 { 101 return _CreateTime; 102 } 103 set { if (value != _CreateTime) { OnPropertyChanging("CreateTime"); _CreateTime = value; OnPropertyChanged("CreateTime"); } } 104 } 105 [Column] 106 public string Title 107 { 108 get { return _Title; } 109 set { if (value != _Title) { OnPropertyChanging("Title"); _Title = value; OnPropertyChanged("Title"); } } 110 } 111 //声明两个事件来实现 112 public event PropertyChangingEventHandler PropertyChanging; 113 public event PropertyChangedEventHandler PropertyChanged; 114 //事件对应的方法 115 protected void OnPropertyChanging(string propertyName) 116 { 117 if (PropertyChanging != null) 118 { 119 PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); 120 } 121 } 122 protected void OnPropertyChanged(string propertyName) 123 { 124 if (PropertyChanged != null) 125 { 126 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 127 } 128 } 129 } 130 #endregion 131 #region 用于操作数据库的上下文 132 public class MyContext : DataContext 133 { 134 //连接字符串 135 public const string CONN_STR = "data source='isostore:/db.sdf';password='123456'"; 136 //公共构造函数 137 public MyContext() : base(CONN_STR) { } 138 //公共成员 139 public Table<Moon> Moons; 140 public Table<Diarys> Diarys; 141 } 142 #endregion 143 }
但是建立好后使用的时候却出现不存在着两张表的错误,但是我单独建立一张表的时候却又能成功,这是为什么呢?