Intern Day96

补充知识

删除数据库中指定id的SQL语句,有以下三种:

  1. delete from 表名 where id=@id;

  2. delete from 表名 where id={userId};

  3. delete from 表名 where id=#{id};

@ 字符的作用

C#字符串中使用转义字符需要加 / 。如果不想多加一个 / 的话,我们可以在字符串前面加上 @ 即可。

即:string p = "//home//ubuntu" 等价于 string p = @"/home/ubuntu"

$ 字符的作用

$ 就可以把{} 放在包含一个变量或表达式的字符串中。

比如:var t = $"update people set is_deleted = true where id = {input.Id};";

接口实现

public async Task<Result> Delete(Input input) 
{
    await _abcService.Delete(input);
    return Result.Ok;
}

接口中Delete方法具体实现

public async Task Delete(Input input)
{
    var del1 = $"update People1 set is_deleted = true where student_id = {input.StudentId};";
    _unitofwork.ExecuteSqlCommand(del1);
            
    var del2 = $"delete from People2 where student_id = {input.StudentId};";
    _unitofwork.ExecuteSqlCommand(del2);
            
            …… …… …… // 更新input(即传入的id)对应的那个类型的相关数据
                
    await _unitofwork.SaveChangesAsync();
}
原文地址:https://www.cnblogs.com/OFSHK/p/14805428.html