當調用上下文的Attach方法將對象附加到上下文時,負序列號應暫時分配給Identity屬性。在我的情況下,該值似乎是永久性的,最終將對象保存到數據庫時會導致錯誤。EF Core將負序號分配給自動增量int字段
public virtual void Insert(TEntity entity)
{
entity.ObjectState = ObjectState.Added;
_dbSet.Attach(entity);
_context.SyncObjectState<TEntity>(entity);
}
public class Tier:Entity
{
public Tier()
{
}
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int TierID { get; set; }
public string CountryID { get; set; }
public string TierName { get; set; }
public int TierNo { get; set; }
public virtual ICollection<AdministrativeStructure> AdministrativeStructures { get; set; }
public Country Country { get; set; }
}
我使用的EntityFramework核心1.1.0與MSSQL服務器2016
是什麼類型的 '一線'? –
請閱讀[問]並提供[mcve]。 – CodeCaster
定義「隨機」 - 每次都是相同的「隨機」數字,還是每個「層次」實例的不同數字? – soupdog