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

  报错:指定对象不在字典中解决方案:

创新互联建站从2013年开始,先为阿克陶等服务建站,阿克陶等地企业,进行企业商务咨询服务。为阿克陶企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

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().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 creatorIds = levelList.Where(l => l.Creator != null).Select(l => l.Creator).Distinct().ToList();
                var creatorDic = dbPlatform.Query().Where(a => creatorIds.Contains(a.Id)).ToDictionary(a => a.Id, a => a.RealName);
                var cList = dbSchool.Query().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();
            }
        }

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


本文标题:……指定对象不在字典中报错解决
标题来源:http://myzitong.com/article/gjjjjj.html