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

Intersect ef中的交集


我在调试的时候,看到2个list有共同的元素,为什么temp.Count() =0呢?


 List<Department> temp = deptBranch.Intersect(deptList).ToList();
                                if (deptBranch.Intersect(deptList).ToList().Count() >= 2)
                                    continue;








完整


        public static bool AddTask(Task task,int[] deptArr=null)
        {
            try
            {
                using (var db = new WEBVODEntities())
                {
                    string loginName = CurrentProject.GetCurrentUser().LoginName;

                    //添加-Task-对象
                    task.TimeCreate = DateTime.Now;
                    task.ManCreate = loginName;
                    task.LoginName = loginName;
                    task.Guid = Guid.NewGuid().ToString();
                    db.Task.AddObject(task);


                    //添加-部门-任务
                    if (deptArr != null && (task.TypeId == Constants.TaskType_Global || task.TypeId == Constants.TaskType_Local))   
                    {
                        List<Department> deptList = db.Department.Where(a => deptArr.Contains(a.Id)).OrderBy(a=>a.Level).ToList(); //级别高的排前边


                        //添加-TaskDept-对象
                        foreach (var dept in deptList)