日期:2014-05-17  浏览次数:20484 次

在 mvc ef 中进行删除

请问下边2中写法,会有什么区别

写法1:
不同的地方:
                    List<Task> taskList = db.Task.Where(a => guidArr.Contains(a.Guid)).ToList();
                    List<TaskDept> taskDeptList = db.TaskDept.Where(a => guidArr.Contains(a.TaskGuid)).ToList();
代码1.完整


        /// <summary>
        /// 任务-批量删除
        /// (2013.5.25)
        /// </summary>
        /// <param name="idArr"></param>
        /// <returns></returns>
        public static bool BatchDelete(string[] guidArr)
        {
            try
            {
                using (var db =new WEBVODEntities())
                {

                    List<Task> taskList = db.Task.Where(a => guidArr.Contains(a.Guid)).ToList();

                    List<TaskDept> taskDeptList = db.TaskDept.Where(a => guidArr.Contains(a.TaskGuid)).ToList();

                    foreach (var task in taskList)
                    {    
                        db.DeleteObject(task);
                    }

                    foreach (var taskDept in taskDeptList)
                    {
                        db.DeleteObject(taskDept);
                    }

                    db.SaveChanges();

                    return true;
                }
            }