删除
2021-11-15 Less than 1 minute
# Demo
本次分表的demo源码:SqlServerShardingAll (opens new window)
# 删除数据
增删改查除了查询稍微在分表+排序的情况下需要注意其实其他操作和efcore基本上一致
删除也是
public async Task<IActionResult> Delete()
{
var sysUser = await _myDbContext.Set<SysUser>().Where(o => o.Id == "9").FirstOrDefaultAsync();
_myDbContext.Remove(sysUser);
var i = await _myDbContext.SaveChangesAsync();
return Ok(i);
}
1
2
3
4
5
6
7
2
3
4
5
6
7
控制台我们可以看到对应的执行sql
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[@p0='?' (Size = 50) (DbType = AnsiString)], CommandType='Text', CommandTimeout='30']
SET NOCOUNT ON;
DELETE FROM [SysUser_00]
WHERE [Id] = @p0;
SELECT @@ROWCOUNT;
1
2
3
4
5
6
2
3
4
5
6