zoukankan      html  css  js  c++  java
  • 第三节: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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
  • 相关阅读:
    delphiXE7关于android 检测屏幕是否处于关闭状态
    delphiXE7关于android API的使用和检测WIFI状态的问题
    关于Android下Delphi XE7获取通讯录的问题
    多线程操里操作webbrowser的 Frames
    关于游戏引擎
    今天博客开通了
    集合类型-集合
    编程语言
    live Python4笔记
    live Python3笔记
  • 原文地址:https://www.cnblogs.com/chenze-Index/p/9288242.html
Copyright © 2011-2022 走看看