Linq 的新手,如果这是基本的,请道歉。当我枚举结果时,此查询抛出错误 {"Cannot cast DBNull.Value to type 'System.Int64'. Please use a nullable type."}。
private void AddLevels(long rootid)
{
var results = from row in data.AsEnumerable()
where row.Field<long>("ParentID") == rootid
select row;
foreach (DataRow row in results)
{
//do stuff
}
}
ParentID 列确实接受空值 - 我需要单独处理这些吗?
EDIT2:下面的实际解决方案仍然使用Linq。
编辑:我通过废弃 Linq 并仅使用 DataTable.Select 语句解决了这个问题。如果有人对性能差异有意见,我会很感兴趣。