当调用上下文的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