温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

……指定对象不在字典中报错解决

发布时间:2020-06-13 00:52:47 来源:网络 阅读:254 作者: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 ? ("管理员创建") : (d.CreateType == 2 ? ("班主任创建班级时自定义") : (d.CreateType == 3 ? ("华网导入") : ("无数据"))),
                    CreateOn = d.CreatedOn.ToString()
                }).Where(d=>d.Value.Contains(model.SArg.Title)) .ToList();
            }
            finally
            {
                dbSchool.Dispose();
                dbPlatform.Dispose();
            }
        }



……指定对象不在字典中报错解决


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI