public void Delete<TEntity>(TEntity entity) where TEntity : class, IEntity
{
this.Configuration.ValidateOnSaveEnabled = false;
if (!this.Set<TEntity>().Local.Any(d => d.Id == entity.Id))
{
this.Set<TEntity>().Attach(entity);
}
this.Set<TEntity>().Remove(entity);
SaveChanges();
this.Configuration.ValidateOnSaveEnabled = true;
}
上面的代码在 SaveChanges() 上引发异常。
[DbUpdateException: Null value for non-nullable member. Member: 'Name'.]
删除实体时如何删除验证?