溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

……指定對象不在字典中報錯解決

發(fā)布時間:2020-06-13 00:52:47 來源:網(wǎng)絡 閱讀:253 作者:dingzhaoqiang 欄目:編程語言

  報錯:指定對象不在字典中解決方案:


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 ? ("管理員創(chuàng)建") : (d.CreateType == 2 ? ("班主任創(chuàng)建班級時自定義") : (d.CreateType == 3 ? ("華網(wǎng)導入") : ("無數(shù)據(jù)"))),
                    CreateOn = d.CreatedOn.ToString()
                }).Where(d=>d.Value.Contains(model.SArg.Title)) .ToList();
            }
            finally
            {
                dbSchool.Dispose();
                dbPlatform.Dispose();
            }
        }



……指定對象不在字典中報錯解決


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI