2012-05-15 41 views
0

我有错误的列Id不能包含空值,但我在IsDbGenerated上设置为true。我究竟做错了什么?自动增量字段没有被自动设置

private int id; 
[Column(IsPrimaryKey=true, CanBeNull=false, DbType="int", IsDbGenerated=true)] 
public int Id 
{ 
    get { return id; } 
    set 
    { 
     if (id != value) 
     { 
      id = value; 
      RaisePropertyChanged("Id"); 
     } 
    } 
} 
+0

怎么样数据库。你有没有在数据库中设置idetity = yes – Tassadaque

+0

它是独立存储中Windows Phone的sdf(SQLce)。 – user384080

+0

http://www.any-ti.me/manually-setting-autoincrement-identity-fields-in-sqlce-31-and-35.aspx – Tassadaque

回答

0

试试这个

private int id; 
    [Column(IsPrimaryKey=true, IsDbGenerated=true, DbType="INT NOT NULL IDENTITY", CanBeNull=false, AutoSync=AutoSync.OnInsert)] 
    public int Id 
    { 
     get { return id; } 
     set 
     { 
      if (id != value) 
      { 
       NotifyPropertyChanging("Id"); 
       id = value; 
       NotifyPropertyChanged("Id"); 
      } 
     } 
    }