Lambda/Linq 错误“已添加具有相同键的项目”
我收到的错误是“已添加具有相同密钥的项目”。我做错了什么?预先感谢您的帮助。
using (var Customerconn = new DataClassesDataContext())
{
Dictionary<int, string> Empsource = Customerconn.tblOutOfOfficeLogs
.Join(Customerconn.tblEmployees,
l => l.EmployeeID,
emp => emp.EmployeeID,
(l, emp) => new { ID = emp.EmployeeID, Name = emp.FirstName + " " + emp.LastName })
.Distinct()
.ToDictionary(empl => empl.ID, empl => empl.Name);
//Set combo box source to Empsource
}
"An item with the same key has already been added" is the error I'm getting. What am I doing wrong? Thank you in advance for any help.
using (var Customerconn = new DataClassesDataContext())
{
Dictionary<int, string> Empsource = Customerconn.tblOutOfOfficeLogs
.Join(Customerconn.tblEmployees,
l => l.EmployeeID,
emp => emp.EmployeeID,
(l, emp) => new { ID = emp.EmployeeID, Name = emp.FirstName + " " + emp.LastName })
.Distinct()
.ToDictionary(empl => empl.ID, empl => empl.Name);
//Set combo box source to Empsource
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使您确定不存在重复的 EmployeeID,如果同一员工持有多个日志,您也可能会在 join 语句中导致重复。这不是你的问题吗?
以下有效吗?
Even though you are sure that no duplicate EmployeeIDs exist you may cause duplicates in the join statement if the same employee holds more than one log. Isn't that your problem?
Does the following work?