我在此方法中收到 Specified cast is not valid 错误
public Dictionary<byte, string> getTeamList(int id1, Dictionary<byte, int> myList)
{
Dictionary<byte, string> result = new Dictionary<byte, string>();
var query= _dataContext.usp_getItem();
foreach(var item in query)
{
if (myList.ContainsKey(item.ID)
{
int count= _dataContext.usp_getCountPerID(id1, item.ID).FirstOrDefault().Count;
if (myList[item.ID] > count)
{
result.Add(item.ID, item.Name);
}
}
else
{
result.Add(item.ID, item.Name);
}
}
return result;
}
我在这一行收到 InvalidCastException 错误:
int count = _dataContext.usp_getCountPerID(item.ID).FirstOrDefault().Count;
Count 的类型是 int。当我注释掉这行代码时它起作用了。
更新
usp_getCountPerID 如下所示:
@ID1 INT,
@ID2 TINYINT
SELECT COUNT(ID) AS Count //I'm changing this name so it's actually not "Count"
FROM Table
WHERE ID1 = @ID1
AND ID2 = @ID2