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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
  • 相关阅读:
    Codeforces Round #650 (Div. 3)
    C. Count Triangles
    A National Pandemic (思维 + 树链剖分模版)
    扫描线专题
    扫描线模版
    莫队模版
    JS设计模式 -- 4种创建型模式
    滑动窗口的最大值 -- 单调队列
    JS链表实现栈和队列
    js数组扁平化的几种实现方式
  • 原文地址:https://www.cnblogs.com/chenze-Index/p/9288242.html
Copyright © 2011-2022 走看看