自动增量字段未自动设置

时间:2012-05-15 10:57:51

标签: windows-phone-7 linq-to-sql

我遇到错误,列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");
        }
    }
}

1 个答案:

答案 0 :(得分: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");
            }
        }
    }
相关问题