标签:报错-不在字典中
报错:指定对象不在字典中解决方案:
Creator = ( creatorDic.ContainsKey(d.Creator.Value) && d.Creator != null) ? creatorDic[d.Creator.Value] : "",
----------------------------------
public void GetList(MLevel model) { if (string.IsNullOrEmpty(model.SArg.Title)) { model.SArg.Title = string.Empty; } if (model.Key == Guid.Empty) { model.SchoolId = TypeKit.ToGuid(YK.School.Core.Context.SchoolId, Guid.Empty); } else { model.SchoolId = model.Key; } var dbSchool = DbContext.SchoolUnitOfWorkCreate(); var dbPlatform = DbContext.PlatformWorkCreate(); try { var query = dbSchool.Query<Sc_Level>().Where(t => t.SchoolId == model.SchoolId); if (!string.IsNullOrEmpty(model.SArg.Title)) { query = query.Where(t => t.LName.Contains(model.SArg.Title)); } model.PArg.RowsCount = query.Count(); query = query.OrderByDescending(d => d.LNo).Skip(model.PArg.FirstRowIndex).Take(model.PArg.PageSize); var levelList = query.ToList(); var lIdList = levelList.Select(d => d.Id); List<Guid?> creatorIds = levelList.Where(l => l.Creator != null).Select(l => l.Creator).Distinct().ToList(); var creatorDic = dbPlatform.Query<LQ_Member>().Where(a => creatorIds.Contains(a.Id)).ToDictionary(a => a.Id, a => a.RealName); var cList = dbSchool.Query<Sc_Class>().Where(c => c.SchoolId == model.SchoolId && c.Sc_LevelId != null && lIdList.Contains(c.Sc_LevelId ?? Guid.Empty)); model.levellist = levelList.Select(d => new MLevel.Level { Key = d.Id, State = cList.Count(c => c.Sc_LevelId == d.Id) > 0 ? ("已引用") : ("未引用"), Value = d.LName, Creator = ( creatorDic.ContainsKey(d.Creator.Value) && d.Creator != null) ? creatorDic[d.Creator.Value] : "", CreateType = d.CreateType == 1 ? ("管理员创建") : (d.CreateType == 2 ? ("班主任创建班级时自定义") : (d.CreateType == 3 ? ("华网导入") : ("无数据"))), CreateOn = d.CreatedOn.ToString() }).Where(d=>d.Value.Contains(model.SArg.Title)) .ToList(); } finally { dbSchool.Dispose(); dbPlatform.Dispose(); } }
本文出自 “wennuanyiran” 博客,请务必保留此出处http://dingzhaoqiang.blog.51cto.com/5601059/1713367
标签:报错-不在字典中
原文地址:http://dingzhaoqiang.blog.51cto.com/5601059/1713367