我正在使用ServiceStack ORMLite嘗試更新數據庫中的記錄。我所有的POCO的實施IHasID接口ServiceStack ORMLite無法更新標識列
public interface IHasId
{
int Id { get; set; }
}
在我的POCO我有以下屬性
private int id;
[ServiceStack.DataAnnotations.Alias("TableName_ID")]
public int Id
{
get { return id; }
set
{
if (value != this.id)
{
this.id = value;
NotifyPropertyChanged("Id");
}
}
}
我的每一個庫類從DataRepositoryBase <牛逼繼承>類具有下列方法:
public virtual T Update(T entity)
{
using (IDbConnection db = CreateDbConnection())
{
db.Update<T>(entity, e => e.Id == entity.Id);
return entity;
}
}
當我呼籲孩子庫我收到以下錯誤此方法:
System.Data.SqlClient.SqlException (0x80131904): Cannot update identity column 'TableName_ID'.
我該如何解決這個錯誤?
我在做什麼錯?
謝謝!
傑里米
謝謝你的工作! – jkruer01
另外,如果不添加[AutoIncrement]數據註釋,我將更新方法更改爲:db.Update(entity);而且也有效。謝謝! –
jkruer01