我需要一些帮助在这里为我的代码。如何使用词典/列表筛选此数据<Document>?
我写了这段代码。
List<Document> doc = SystemOperationManager.GetSalesByMemberLucene(ConfigurationManager.GetIndexPath(), memberId).ToList();
Dictionary<string, Department> _allDepartments = DepartmentManager.GetAll().ToDictionary(s => s.Id.ToString(), s => s);
Dictionary<string, User> _allUsers = UserManager.GetAll().ToDictionary(s => s.Id.ToString(), s => s);
Dictionary<string, Product> _allProducts = ProductManager.GetAll().Where(x => x.CustomType == 2).ToDictionary(s => s.Id.ToString(), s => s);
List<SystemOperation> so = doc.Select(s => new SystemOperation
{
ObjStylist = s.Get("ObjStylist") != null ? _allUsers[s.Get("ObjStylist")] : null,
ObjDepartment = s.Get("ObjDepartment") != null ? _allDepartments[s.Get("ObjDepartment")] : null,
ObjProduct = s.Get("ObjProduct") != null ? _allProducts[s.Get("ObjProduct")] : null
//TotalPointsCollected = decimal.Parse(s.Get("TotalPointsCollected")),
//PointsAccumulated = decimal.Parse(s.Get("PointsAccumulated"))
}).ToList();
_result = so;
rgList.DataSource = _result;
rgList.DataBind();
当我运行的代码它说,它有这个错误。
类型“System.Collections.Generic.KeyNotFoundException”的一个例外发生在mscorlib.dll但在用户代码中没有处理
附加信息:给定的键不存在在词典中。
任何人都可以帮我解决它吗?
请提供完整的例外WITH stacktrace或至少是发生此错误的行。 –
你必须检查每个字典查找'if(yourdictionary.ConatiansKey(“yourkey”))'.... – Milen
什么样的类是'SystemOperation'?它是什么方法'Get'做什么,它返回什么? –