官方文档https://entityframework-plus.net/ef-core-batch-delete
[HttpGet("DeleteXXX/{ids}")]
public JObject DeleteViews
(String ids)
{
using (XContext db = new XContext())
{
String[] arr = ids.Split(",");
int deletecode = 0;
for (int i = 0; i < arr.Length; i++)
{
deletecode += db.Views.DeleteByKey(arr[i]);
}
db.SaveChanges();//必须保存,否则只是临时标记为删除而已
if (deletecode > 0)
{
return XUtil.CreateResult(0, "删除完成,已删除" + deletecode + "条");
}
else
{
return XUtil.CreateResult(-1, "删除失败,可能已删除");
}
}
}