错误原因:deptList 没有ToList,没有ToList,查询就没有执行,正确写法
var ids = SelID.Split(',').Select(int.Parse).ToArray(); var deptList = db.Sys_DistrictInfo.Where(t => ids.Contains(t.DisID)).ToList(); var list = deptList.Select(t => new P_EmpDis() { UserID = UserID, EntID = t.EntID, DisClass = t.DisClass, DisID = t.DisID, CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }).ToList(); DeleteExp(t => t.UserID == UserID && t.EntID == EntID); return AddCollect(list) > 0;