1

我已经在 windows phone 7 平台上创建了一个数据库。表之一定义如下。

[Table]
public class Playlist : BaseTable
{
    // Define ID: private field, public property, and database column.
    private int _id;

    [Column(DbType = "INT NOT NULL IDENTITY", IsDbGenerated = false, CanBeNull=false, IsPrimaryKey = true)]
    public int Id
    {
        get { return _id; }
        set
        {
            NotifyPropertyChanging("PlaylistId");
            _id = value;
            NotifyPropertyChanged("PlaylistId");
        }
    }
    // some other field
    //.......

}

我不希望字段“id”由db生成,因此“IsDbGenerated = false”,但插入一条记录时出现异常:db.Playlists.InsertOnSubmit(new Playlist { Id = (int)DefalutPlaylist.Default , Name = "默认播放列表", Group = 0, Type = 0 });

它说“无法修改列[列名= id]”

谁能帮我...

4

1 回答 1

4

在 DbType 中删除“INDENTITY”值,如下所示:

[Column(DbType = "INT NOT NULL", IsDbGenerated = false, CanBeNull=false, IsPrimaryKey = true)]

干杯

于 2012-06-27T11:48:25.790 回答