ho folowing entitàtrattati i mapping di colonna SQLite autoincremento in LinqToSql
[Table(Name = "Users")]
public sealed class UserDB
{
private Int64 _id = -1;
private string _username = string.Empty;
public UserDB() { }
public UserDB(RepositoryInfo repoInfo)
{
UserName = repoInfo.Account;
}
[Column(Name = "ID", Storage = "_id", IsDbGenerated = true, IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
public Int64 ID { get { return _id; } set { _id = value; } }
[Column(Name = "UserName", DbType="nvarchar(50)", Storage = "_username")]
public string UserName { get { return _username; } set { _username = value; } }
}
ID è mappato autoincremento INTEGER colonna (in realtà il solo tipo possibile con AutoIncrement in SQLite)
Quando Provo ad aggiungere un nuovo utente a DB come questo, ottengo un errore:
public static Int64 AddUser(DataContext context, RepositoryInfo repoInfo)
{
UserDB udb = new UserDB(repoInfo);
//an ID of udb is -1, but I tried different values too, doesn't change result
var userstable = context.GetTable<UserDB>();
userstable.InsertOnSubmit(udb);
context.SubmitChanges(); // here I get a error, see on screen shot
return udb.ID;
}
EDIT Dopo un googling per e controllo, sembra che SQLite semplicemente non fornisce alcuna funzione SCOPE_IDENTITY()
. Ma Linq To SQL lo inietta!
Come posso modificare questo?