我无法让这段代码正常工作。
DataTable dt = DataManager.GetSectionIdByEmail(test2PortalConnectionString, email);
Dictionary<int,int> clientViewIds = dt.Select(p => new {p.Key, p.Value })
.AsEnumerable()
.ToDictionary(kvp => kvp.key as int, kvp => kvp.Value as int);
我得到的错误是:无法将 lambda 表达式转换为类型“字符串”,因为它不是委托类型
解决方法:我在语句中的 AsEnumberable() 位置错误,我需要处理数据行。
Dictionary<int,int> clientViewIds = dt.AsEnumerable()
.Select(dr => new { Key = dr["SectionID"], Value = dr["SectionTypeID"] })
.ToDictionary(kvp =>(int)kvp.Key, kvp => (int)kvp.Value);