您好,登錄后才能下訂單哦!
報錯:指定對象不在字典中解決方案:
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(); } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。