• 第三节:EF


    1.删除要进行判空

    public ActionResult DelClassMethod(string gId)
            {
                //根据gId查询对应条目
                var grade = oc.BllSession.IGradeBLL.Entities.Where(a => a.gId == gId).FirstOrDefault();
                var stuInfo = oc.BllSession.IStuInfoBLL.Entities.Where(b => b.gId == gId).FirstOrDefault();
                //进行删除
                if (stuInfo != null)
                {
                    oc.BllSession.IStuInfoBLL.DelNo(stuInfo);
                }
                if (grade != null)
                {
                    oc.BllSession.IGradeBLL.DelNo(grade);
                }
    
    
                int result = oc.BllSession.IGradeBLL.SaveChange();
                if (result > 0)
                {
                    return Content("ok");
                }
                else
                {
                    return Content("error");
                }
            }
    View Code

    2.批量删除

     1         public ActionResult DelStuMethod(string idsStr)
     2         {
     3             //进行字符串拆分
     4             string[] str = idsStr.Split(new char[] { ',' });
     5             int[] str_int = Array.ConvertAll(str, int.Parse);
     6             List<int> stuIdList = str_int.ToList();
     7             var stuList = oc.BllSession.IStuInfoBLL.Entities.Where(a => stuIdList.Contains(a.sId)).ToList();
     8             //删除操作
     9             foreach (var item in stuList)
    10             {
    11                 oc.BllSession.IStuInfoBLL.DelNo(item);
    12             }
    13             int result = oc.BllSession.IGradeBLL.SaveChange();
    14 
    15             //int result = oc.BllSession.IStuInfoBLL.DelBy(a => stuIdList.Contains(a.sId));
    16             if (result > 0)
    17             {
    18                 return Content("ok");
    19             }
    20             else
    21             {
    22                 return Content("error");
    23             }
    24         }
    View Code
    作者:chenze
    出处:https://www.cnblogs.com/chenze-Index/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
  • 相关阅读:
    DevExpress v17.2新版亮点——CodeRush篇(三)
    DevExpress v17.2新版亮点——CodeRush篇(二)
    DevExpress v17.2新版亮点——CodeRush篇(一)
    MySQL性能优化
    什么是MongoDB?
    Redis的两种持久化方式对比
    Redis
    十六、Node.js-fs模块-流
    js中const,var,let区别
    十五、Node.js-fs模块(中)
  • 原文地址:https://www.cnblogs.com/chenze-Index/p/9288242.html
Copyright © 2020-2023  润新知