efcore 第三方扩展批量删除id的高效实现

2022-09-16  本文已影响0人  吉凶以情迁

官方文档
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, "删除失败,可能已删除");

                }
            }

        }

上一篇下一篇

猜你喜欢

热点阅读