使用 Insertable + ExecuteReturnSnowflakeIdAsync 爲Id賦值時Id字段不能自增
數據庫爲SqlServer2012,實體的Id
字段標記IsPrimaryKey = true
屬性,新增時使用雪花算法創建Id並將其賦值給新增記錄,此時數據表Id
字段不能設置爲自增,否則插入失敗,報SqlException
。因此,打算自己管理Id時就從數據表開始不讓其自動分配。
public class EntityExample{
[SugarColumn(IsPrimaryKey = true, ColumnName = "Id", IsOnlyIgnoreUpdate = true)]
public long Id {get; set;}
}
long Id = await Db.Insertable<ThirdpartyUserInfoModel>(model)
.ExecuteReturnSnowflakeIdAsync();